@d0paminedriven/fs 6.5.0 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -12
- package/dist/{chunk-O4BKLMFV.js → chunk-CN45SMBB.js} +16 -1
- package/dist/{chunk-Y3TLKN7F.js → chunk-CTA73JRX.js} +321 -48
- package/dist/{chunk-MXEE2WS7.js → chunk-G27YIWW7.js} +1 -1
- package/dist/fs/index.cjs +333 -45
- package/dist/fs/index.d.cts +62 -10
- package/dist/fs/index.d.ts +62 -10
- package/dist/fs/index.js +3 -3
- package/dist/index.cjs +333 -45
- package/dist/index.js +3 -3
- package/dist/mime/index.cjs +15 -0
- package/dist/mime/index.d.cts +4 -3
- package/dist/mime/index.d.ts +4 -3
- package/dist/mime/index.js +1 -1
- package/dist/types/index.d.cts +9 -1
- package/dist/types/index.d.ts +9 -1
- package/dist/types/index.js +1 -1
- package/package.json +12 -3
package/dist/fs/index.cjs
CHANGED
|
@@ -459,6 +459,21 @@ var MimeService = class extends UrlService {
|
|
|
459
459
|
);
|
|
460
460
|
}
|
|
461
461
|
}
|
|
462
|
+
mimeToExt(mime) {
|
|
463
|
+
const extensions = this.toExtObj[mime];
|
|
464
|
+
if (extensions.length === 1) return extensions[0];
|
|
465
|
+
if (extensions.length === 2) {
|
|
466
|
+
return extensions[0];
|
|
467
|
+
}
|
|
468
|
+
if (extensions.length === 3) {
|
|
469
|
+
if (mime === "audio/ogg") return "ogg";
|
|
470
|
+
return extensions[0];
|
|
471
|
+
}
|
|
472
|
+
if (extensions.length === 5) {
|
|
473
|
+
return "sse";
|
|
474
|
+
}
|
|
475
|
+
return extensions[0];
|
|
476
|
+
}
|
|
462
477
|
assetType(url) {
|
|
463
478
|
const parsed = this.parseUrl(url);
|
|
464
479
|
if (!parsed) return void 0;
|
|
@@ -498,7 +513,7 @@ var unitsObj = {
|
|
|
498
513
|
};
|
|
499
514
|
|
|
500
515
|
// src/fs/index.ts
|
|
501
|
-
dotenv.config();
|
|
516
|
+
dotenv.config({ quiet: true });
|
|
502
517
|
var Fs = class extends MimeService {
|
|
503
518
|
constructor(cwd) {
|
|
504
519
|
super();
|
|
@@ -818,7 +833,6 @@ var Fs = class extends MimeService {
|
|
|
818
833
|
if (!response.ok) {
|
|
819
834
|
throw new Error(`Failed to fetch asset: ${response.statusText}`);
|
|
820
835
|
}
|
|
821
|
-
console.log(Object.fromEntries(Array.from(response.headers.entries())));
|
|
822
836
|
const reader = response.body?.getReader();
|
|
823
837
|
if (reader) {
|
|
824
838
|
const chunks = Array.of();
|
|
@@ -885,6 +899,38 @@ var Fs = class extends MimeService {
|
|
|
885
899
|
return console.error(err);
|
|
886
900
|
}
|
|
887
901
|
}
|
|
902
|
+
parseExif(buffer, app1Pos, _app1Size) {
|
|
903
|
+
const exifHeader = buffer.toString("ascii", app1Pos + 2, app1Pos + 8);
|
|
904
|
+
if (exifHeader !== "Exif\0\0")
|
|
905
|
+
return { orientation: null, dateTimeOriginal: null };
|
|
906
|
+
let tiffPos = app1Pos + 8;
|
|
907
|
+
const byteOrder = buffer.toString("ascii", tiffPos, tiffPos + 2);
|
|
908
|
+
const littleEndian = byteOrder === "II";
|
|
909
|
+
const readUInt16 = littleEndian ? buffer.readUInt16LE.bind(buffer) : buffer.readUInt16BE.bind(buffer);
|
|
910
|
+
const readUInt32 = littleEndian ? buffer.readUInt32LE.bind(buffer) : buffer.readUInt32BE.bind(buffer);
|
|
911
|
+
if (readUInt16(tiffPos + 2) !== 42)
|
|
912
|
+
return { orientation: null, dateTimeOriginal: null };
|
|
913
|
+
let ifdOffset = readUInt32(tiffPos + 4);
|
|
914
|
+
tiffPos += ifdOffset;
|
|
915
|
+
const numEntries = readUInt16(tiffPos);
|
|
916
|
+
tiffPos += 2;
|
|
917
|
+
let orientation = null;
|
|
918
|
+
let dateTimeOriginal = null;
|
|
919
|
+
for (let i = 0; i < numEntries; i++) {
|
|
920
|
+
const tag = readUInt16(tiffPos);
|
|
921
|
+
const type = readUInt16(tiffPos + 2);
|
|
922
|
+
const count = readUInt32(tiffPos + 4);
|
|
923
|
+
const valueOffset = tiffPos + 8;
|
|
924
|
+
if (tag === 274 && type === 3 && count === 1) {
|
|
925
|
+
orientation = readUInt16(valueOffset);
|
|
926
|
+
} else if (tag === 36867 && type === 2 && count === 20) {
|
|
927
|
+
const offset = readUInt32(valueOffset);
|
|
928
|
+
dateTimeOriginal = buffer.toString("ascii", app1Pos + 2 + offset, app1Pos + 2 + offset + 19).trim();
|
|
929
|
+
}
|
|
930
|
+
tiffPos += 12;
|
|
931
|
+
}
|
|
932
|
+
return { orientation, dateTimeOriginal };
|
|
933
|
+
}
|
|
888
934
|
/**
|
|
889
935
|
*
|
|
890
936
|
* @param inputUrl remote url to fetch data from
|
|
@@ -965,20 +1011,82 @@ var Fs = class extends MimeService {
|
|
|
965
1011
|
}
|
|
966
1012
|
return null;
|
|
967
1013
|
}
|
|
968
|
-
async
|
|
1014
|
+
async getImageSpecs(filePath) {
|
|
969
1015
|
const buffer = await this.fileToBufferAsync(filePath);
|
|
970
1016
|
if (buffer?.length >= 24 && buffer?.[0] === 137 && buffer?.[1] === 80 && buffer?.[2] === 78 && buffer?.[3] === 71 && buffer?.[4] === 13 && buffer?.[5] === 10 && buffer?.[6] === 26 && buffer?.[7] === 10) {
|
|
971
1017
|
if (buffer.readUint32BE(8) !== 13 || buffer?.[12] !== 73 || buffer?.[13] !== 72 || buffer?.[14] !== 68 || buffer?.[15] !== 82) {
|
|
972
1018
|
throw new Error("IHDR Chunk of png not found or incorrect.");
|
|
973
1019
|
}
|
|
1020
|
+
const colorType = buffer[25];
|
|
1021
|
+
let colorSpace;
|
|
1022
|
+
let hasAlpha = false;
|
|
1023
|
+
switch (colorType) {
|
|
1024
|
+
case 0:
|
|
1025
|
+
colorSpace = "grayscale";
|
|
1026
|
+
break;
|
|
1027
|
+
case 2:
|
|
1028
|
+
colorSpace = "rgb";
|
|
1029
|
+
break;
|
|
1030
|
+
case 3:
|
|
1031
|
+
colorSpace = "indexed";
|
|
1032
|
+
break;
|
|
1033
|
+
case 4:
|
|
1034
|
+
colorSpace = "grayscale-alpha";
|
|
1035
|
+
hasAlpha = true;
|
|
1036
|
+
break;
|
|
1037
|
+
case 6:
|
|
1038
|
+
colorSpace = "rgba";
|
|
1039
|
+
hasAlpha = true;
|
|
1040
|
+
break;
|
|
1041
|
+
default:
|
|
1042
|
+
colorSpace = "unknown";
|
|
1043
|
+
}
|
|
1044
|
+
const width = buffer.readUInt32BE(16);
|
|
1045
|
+
const height = buffer.readUInt32BE(20);
|
|
1046
|
+
let frames = 1;
|
|
1047
|
+
let animated = false;
|
|
1048
|
+
let iccProfile = null;
|
|
1049
|
+
let exifDateTimeOriginal = null;
|
|
1050
|
+
let orientation = null;
|
|
1051
|
+
let pos = 33;
|
|
1052
|
+
while (pos < buffer.length - 12) {
|
|
1053
|
+
const chunkLen = buffer.readUInt32BE(pos);
|
|
1054
|
+
const chunkType = buffer.toString("ascii", pos + 4, pos + 8);
|
|
1055
|
+
const chunkData = pos + 8;
|
|
1056
|
+
if (chunkType === "acTL") {
|
|
1057
|
+
animated = true;
|
|
1058
|
+
frames = buffer.readUInt32BE(chunkData);
|
|
1059
|
+
} else if (chunkType === "iCCP") {
|
|
1060
|
+
const nameEnd = buffer.indexOf(0, chunkData);
|
|
1061
|
+
const profileName = buffer.toString("ascii", chunkData, nameEnd);
|
|
1062
|
+
iccProfile = profileName || "embedded";
|
|
1063
|
+
} else if (chunkType === "tIME") {
|
|
1064
|
+
const month = buffer?.[chunkData + 2], day = buffer?.[chunkData + 3], hour = buffer?.[chunkData + 4], minute = buffer?.[chunkData + 5], second = buffer?.[chunkData + 6];
|
|
1065
|
+
if (typeof month !== "undefined" && typeof day !== "undefined" && typeof hour !== "undefined" && typeof minute !== "undefined" && typeof second !== "undefined") {
|
|
1066
|
+
const year = buffer.readUInt16BE(chunkData);
|
|
1067
|
+
exifDateTimeOriginal = `${year}:${month.toString().padStart(2, "0")}:${day.toString().padStart(2, "0")} ${hour.toString().padStart(2, "0")}:${minute.toString().padStart(2, "0")}:${second.toString().padStart(2, "0")}`;
|
|
1068
|
+
}
|
|
1069
|
+
} else if (chunkType === "IDAT") {
|
|
1070
|
+
break;
|
|
1071
|
+
}
|
|
1072
|
+
pos += 12 + chunkLen;
|
|
1073
|
+
}
|
|
974
1074
|
return {
|
|
975
|
-
width
|
|
976
|
-
height
|
|
977
|
-
|
|
1075
|
+
width,
|
|
1076
|
+
height,
|
|
1077
|
+
format: "png",
|
|
1078
|
+
frames,
|
|
1079
|
+
animated,
|
|
1080
|
+
hasAlpha,
|
|
1081
|
+
orientation,
|
|
1082
|
+
aspectRatio: width / height,
|
|
1083
|
+
colorSpace,
|
|
1084
|
+
iccProfile,
|
|
1085
|
+
exifDateTimeOriginal
|
|
978
1086
|
};
|
|
979
1087
|
}
|
|
980
1088
|
if (buffer.length >= 10 && buffer[0] === 255 && buffer[1] === 216) {
|
|
981
|
-
let pos = 2;
|
|
1089
|
+
let pos = 2, colorSpace = "unknown", hasAlpha = false, width = 0, height = 0, iccProfile = null, orientation = null, exifDateTimeOriginal = null;
|
|
982
1090
|
while (pos < buffer.length - 10) {
|
|
983
1091
|
if (buffer[pos] !== 255) {
|
|
984
1092
|
throw new Error("Invalid JPEG file");
|
|
@@ -990,34 +1098,148 @@ var Fs = class extends MimeService {
|
|
|
990
1098
|
throw new Error("no marker for jpeg");
|
|
991
1099
|
}
|
|
992
1100
|
if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1101
|
+
const numComponents = buffer[pos + 4];
|
|
1102
|
+
switch (numComponents) {
|
|
1103
|
+
case 1:
|
|
1104
|
+
colorSpace = "grayscale";
|
|
1105
|
+
break;
|
|
1106
|
+
case 3:
|
|
1107
|
+
colorSpace = "ycbcr";
|
|
1108
|
+
break;
|
|
1109
|
+
// Most common for RGB JPEGs (stored as YCbCr)
|
|
1110
|
+
case 4:
|
|
1111
|
+
colorSpace = "ycck";
|
|
1112
|
+
break;
|
|
1113
|
+
// YCCK for CMYK with alpha-like, but no true alpha
|
|
1114
|
+
default:
|
|
1115
|
+
colorSpace = "unknown";
|
|
1116
|
+
}
|
|
1117
|
+
width = buffer.readUInt16BE(pos + 7);
|
|
1118
|
+
height = buffer.readUInt16BE(pos + 5);
|
|
1119
|
+
} else if (marker === 225) {
|
|
1120
|
+
const { orientation: ori, dateTimeOriginal } = this.parseExif(
|
|
1121
|
+
buffer,
|
|
1122
|
+
pos,
|
|
1123
|
+
segmentSize
|
|
1124
|
+
);
|
|
1125
|
+
orientation = ori;
|
|
1126
|
+
exifDateTimeOriginal = dateTimeOriginal;
|
|
1127
|
+
} else if (marker === 226) {
|
|
1128
|
+
const iccHeader = buffer.toString("ascii", pos + 4, pos + 18);
|
|
1129
|
+
if (iccHeader.startsWith("ICC_PROFILE")) {
|
|
1130
|
+
iccProfile = "embedded";
|
|
1131
|
+
}
|
|
998
1132
|
}
|
|
999
1133
|
pos += segmentSize + 2;
|
|
1000
1134
|
}
|
|
1001
|
-
throw new Error("No dimensions found in JPEG file");
|
|
1135
|
+
if (width === 0) throw new Error("No dimensions found in JPEG file");
|
|
1136
|
+
return {
|
|
1137
|
+
width,
|
|
1138
|
+
height,
|
|
1139
|
+
format: "jpeg",
|
|
1140
|
+
frames: 1,
|
|
1141
|
+
animated: false,
|
|
1142
|
+
// JPEG not animated
|
|
1143
|
+
hasAlpha,
|
|
1144
|
+
orientation,
|
|
1145
|
+
aspectRatio: width / height,
|
|
1146
|
+
colorSpace,
|
|
1147
|
+
iccProfile,
|
|
1148
|
+
exifDateTimeOriginal
|
|
1149
|
+
};
|
|
1002
1150
|
}
|
|
1003
1151
|
const gifHeader = buffer.toString("ascii", 0, 6);
|
|
1004
1152
|
if (buffer.length >= 10 && (gifHeader === "GIF87a" || gifHeader === "GIF89a")) {
|
|
1153
|
+
const width = buffer.readUInt16LE(6), height = buffer.readUInt16LE(8);
|
|
1154
|
+
let frames = 0;
|
|
1155
|
+
let pos = 13;
|
|
1156
|
+
let bufTen = buffer?.[10];
|
|
1157
|
+
if (typeof bufTen === "undefined") {
|
|
1158
|
+
pos = 13;
|
|
1159
|
+
frames = 0;
|
|
1160
|
+
} else if (bufTen & 128) pos += 3 << (bufTen & 7) + 1;
|
|
1161
|
+
while (pos < buffer.length) {
|
|
1162
|
+
if (buffer[pos] === 33) {
|
|
1163
|
+
pos += 2;
|
|
1164
|
+
let subSize = buffer?.[pos];
|
|
1165
|
+
while (subSize && subSize > 0) {
|
|
1166
|
+
pos += subSize + 1;
|
|
1167
|
+
subSize = buffer?.[pos];
|
|
1168
|
+
}
|
|
1169
|
+
pos++;
|
|
1170
|
+
} else if (buffer?.[pos] && buffer?.[pos] === 44) {
|
|
1171
|
+
frames++;
|
|
1172
|
+
pos += 10;
|
|
1173
|
+
let b = buffer?.[pos - 1];
|
|
1174
|
+
if (typeof b !== "undefined" && b & 128)
|
|
1175
|
+
pos += 3 << (b & 7) + 1;
|
|
1176
|
+
pos++;
|
|
1177
|
+
let dataSize = buffer?.[pos];
|
|
1178
|
+
while (dataSize && dataSize > 0) {
|
|
1179
|
+
pos += dataSize + 1;
|
|
1180
|
+
dataSize = buffer[pos];
|
|
1181
|
+
}
|
|
1182
|
+
pos++;
|
|
1183
|
+
} else if (buffer[pos] === 59) {
|
|
1184
|
+
break;
|
|
1185
|
+
} else {
|
|
1186
|
+
pos++;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1005
1189
|
return {
|
|
1006
|
-
width
|
|
1007
|
-
height
|
|
1008
|
-
|
|
1190
|
+
width,
|
|
1191
|
+
height,
|
|
1192
|
+
format: "gif",
|
|
1193
|
+
frames,
|
|
1194
|
+
animated: frames > 1,
|
|
1195
|
+
hasAlpha: null,
|
|
1196
|
+
// GIF transparency is per-pixel binary, not full alpha; set null or true if transparent color exists, but complex
|
|
1197
|
+
orientation: null,
|
|
1198
|
+
// No orientation in GIF
|
|
1199
|
+
aspectRatio: width / height,
|
|
1200
|
+
colorSpace: "indexed",
|
|
1201
|
+
iccProfile: null,
|
|
1202
|
+
// No ICC in GIF
|
|
1203
|
+
exifDateTimeOriginal: null
|
|
1204
|
+
// No EXIF in GIF
|
|
1009
1205
|
};
|
|
1010
1206
|
}
|
|
1011
|
-
if (buffer.length >= 26 && buffer[0] === 66 && buffer[1] === 77) {
|
|
1207
|
+
if (buffer.length >= 26 && buffer?.[0] === 66 && buffer?.[1] === 77) {
|
|
1208
|
+
const width = buffer.readInt32LE(18);
|
|
1209
|
+
const height = Math.abs(buffer.readInt32LE(22));
|
|
1210
|
+
const bitDepth = buffer.readUInt16LE(28);
|
|
1211
|
+
let colorSpace = bitDepth <= 8 ? "indexed" : "rgb";
|
|
1012
1212
|
return {
|
|
1013
|
-
width
|
|
1014
|
-
height
|
|
1015
|
-
|
|
1213
|
+
width,
|
|
1214
|
+
height,
|
|
1215
|
+
format: "bmp",
|
|
1216
|
+
frames: 1,
|
|
1217
|
+
animated: false,
|
|
1218
|
+
hasAlpha: null,
|
|
1219
|
+
// Some BMP have alpha in 32bpp, check if bitDepth===32 && compression===3 (bitfields with alpha)
|
|
1220
|
+
orientation: buffer.readInt32LE(22) < 0 ? 1 : 6,
|
|
1221
|
+
// Negative height means top-down (orientation 1), positive bottom-up (like 6, but simplified)
|
|
1222
|
+
aspectRatio: width / height,
|
|
1223
|
+
colorSpace,
|
|
1224
|
+
iccProfile: null,
|
|
1225
|
+
// Rare in BMP
|
|
1226
|
+
exifDateTimeOriginal: null
|
|
1016
1227
|
};
|
|
1017
1228
|
}
|
|
1018
1229
|
if (buffer.length >= 30 && buffer.toString("ascii", 0, 4) === "RIFF" && buffer.toString("ascii", 8, 12) === "WEBP") {
|
|
1019
1230
|
const chunkType = buffer.toString("ascii", 12, 16);
|
|
1231
|
+
let colorSpace = "unknown";
|
|
1232
|
+
let hasAlpha = false;
|
|
1233
|
+
let width = 0;
|
|
1234
|
+
let height = 0;
|
|
1235
|
+
let frames = 1;
|
|
1236
|
+
let animated = false;
|
|
1237
|
+
let iccProfile = null;
|
|
1020
1238
|
if (chunkType === "VP8X") {
|
|
1239
|
+
const flags = buffer?.[20];
|
|
1240
|
+
colorSpace = flags ? flags & 2 ? "rgba" : "rgb" : "unknown";
|
|
1241
|
+
hasAlpha = flags ? !!(flags & 2) : false;
|
|
1242
|
+
animated = flags ? !!(flags & 1) : false;
|
|
1021
1243
|
let widthSubtractOne = 0;
|
|
1022
1244
|
let heightSubtractOne = 0;
|
|
1023
1245
|
if (buffer?.[24] && buffer?.[25] && buffer?.[26]) {
|
|
@@ -1026,48 +1248,70 @@ var Fs = class extends MimeService {
|
|
|
1026
1248
|
if (buffer?.[27] && buffer?.[28] && buffer?.[29]) {
|
|
1027
1249
|
heightSubtractOne = buffer[27] | buffer[28] << 8 | buffer[29] << 16;
|
|
1028
1250
|
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1251
|
+
width = widthSubtractOne + 1;
|
|
1252
|
+
height = heightSubtractOne + 1;
|
|
1253
|
+
if (animated) {
|
|
1254
|
+
let pos = 30;
|
|
1255
|
+
frames = 0;
|
|
1256
|
+
while (pos < buffer.length - 8) {
|
|
1257
|
+
const subChunkType = buffer.toString("ascii", pos, pos + 4);
|
|
1258
|
+
const subChunkSize = buffer.readUInt32LE(pos + 4);
|
|
1259
|
+
if (subChunkType === "ICCP") {
|
|
1260
|
+
iccProfile = "embedded";
|
|
1261
|
+
} else if (subChunkType === "ANMF") {
|
|
1262
|
+
frames++;
|
|
1263
|
+
}
|
|
1264
|
+
pos += 8 + subChunkSize + subChunkSize % 2;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1034
1267
|
} else if (chunkType === "VP8 ") {
|
|
1268
|
+
colorSpace = "rgb";
|
|
1269
|
+
hasAlpha = false;
|
|
1035
1270
|
const dataStart = 20;
|
|
1036
|
-
if (buffer[dataStart + 3] !== 157 || buffer[dataStart + 4] !== 1 || buffer[dataStart + 5] !== 42) {
|
|
1271
|
+
if (buffer?.[dataStart + 3] !== 157 || buffer?.[dataStart + 4] !== 1 || buffer?.[dataStart + 5] !== 42) {
|
|
1037
1272
|
throw new Error("Invalid VP8 keyframe");
|
|
1038
1273
|
}
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
return {
|
|
1042
|
-
width,
|
|
1043
|
-
height,
|
|
1044
|
-
type: "webp"
|
|
1045
|
-
};
|
|
1274
|
+
width = buffer.readUInt16LE(dataStart + 6) & 16383;
|
|
1275
|
+
height = buffer.readUInt16LE(dataStart + 8) & 16383;
|
|
1046
1276
|
} else if (chunkType === "VP8L") {
|
|
1047
1277
|
const dataStart = 20;
|
|
1048
|
-
if (buffer[dataStart] !== 47) {
|
|
1278
|
+
if (buffer?.[dataStart] !== 47) {
|
|
1049
1279
|
throw new Error("Invalid VP8L signature");
|
|
1050
1280
|
}
|
|
1051
1281
|
const bits = buffer.readUInt32LE(dataStart + 1);
|
|
1052
1282
|
if (bits >>> 29 !== 0) {
|
|
1053
1283
|
throw new Error("Invalid VP8L version");
|
|
1054
1284
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
};
|
|
1285
|
+
colorSpace = bits & 1 << 8 ? "rgba" : "rgb";
|
|
1286
|
+
hasAlpha = !!(bits & 1 << 8);
|
|
1287
|
+
width = 1 + (bits & 16383);
|
|
1288
|
+
height = 1 + (bits >> 14 & 16383);
|
|
1289
|
+
} else {
|
|
1290
|
+
throw new Error("Unsupported WebP chunk");
|
|
1062
1291
|
}
|
|
1063
|
-
|
|
1292
|
+
return {
|
|
1293
|
+
width,
|
|
1294
|
+
height,
|
|
1295
|
+
format: "webp",
|
|
1296
|
+
frames,
|
|
1297
|
+
animated,
|
|
1298
|
+
hasAlpha,
|
|
1299
|
+
orientation: null,
|
|
1300
|
+
// No standard orientation in WebP
|
|
1301
|
+
aspectRatio: width / height,
|
|
1302
|
+
colorSpace,
|
|
1303
|
+
iccProfile,
|
|
1304
|
+
exifDateTimeOriginal: null
|
|
1305
|
+
// Can have EXIF chunk, but rare; add if needed
|
|
1306
|
+
};
|
|
1064
1307
|
}
|
|
1065
1308
|
if (buffer.length >= 32 && buffer.toString("ascii", 4, 8) === "ftyp") {
|
|
1066
1309
|
const ftyp = this.findBox(buffer, "ftyp");
|
|
1067
1310
|
if (!ftyp) throw new Error("Invalid AVIF: No ftyp");
|
|
1068
1311
|
const brands = buffer.toString("ascii", ftyp.pos, ftyp.pos + ftyp.size);
|
|
1069
|
-
|
|
1070
|
-
|
|
1312
|
+
const isAvif = brands.includes("avif");
|
|
1313
|
+
const isAvis = brands.includes("avis");
|
|
1314
|
+
if (!isAvif && !isAvis) throw new Error("Not an AVIF file");
|
|
1071
1315
|
const meta = this.findBox(buffer, "meta");
|
|
1072
1316
|
if (!meta) throw new Error("Invalid AVIF: No meta");
|
|
1073
1317
|
const metaSubStart = meta.pos + 4;
|
|
@@ -1081,10 +1325,54 @@ var Fs = class extends MimeService {
|
|
|
1081
1325
|
if (buffer[ispe.pos] !== 0) throw new Error("Invalid ispe version");
|
|
1082
1326
|
const width = buffer.readUInt32BE(ispe.pos + 4);
|
|
1083
1327
|
const height = buffer.readUInt32BE(ispe.pos + 8);
|
|
1328
|
+
let colorSpace = "rgb";
|
|
1329
|
+
let hasAlpha = false;
|
|
1330
|
+
let iccProfile = null;
|
|
1331
|
+
const colr = this.findBox(buffer, "colr", ipco.pos, ipco.pos + ipco.size);
|
|
1332
|
+
if (colr) {
|
|
1333
|
+
const colrType = buffer.toString("ascii", colr.pos, colr.pos + 4);
|
|
1334
|
+
if (colrType === "nclx") {
|
|
1335
|
+
const matrix = buffer.readUInt16BE(colr.pos + 6);
|
|
1336
|
+
colorSpace = matrix === 2 ? "rgb" : "ycbcr";
|
|
1337
|
+
} else if (colrType === "rICC" || colrType === "prof") {
|
|
1338
|
+
colorSpace = "unknown";
|
|
1339
|
+
iccProfile = "embedded";
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
const auxC = this.findBox(buffer, "auxC", ipco.pos, ipco.pos + ipco.size);
|
|
1343
|
+
if (auxC && buffer.toString("ascii", auxC.pos, auxC.pos + auxC.size).includes("alpha")) {
|
|
1344
|
+
hasAlpha = true;
|
|
1345
|
+
if (colorSpace === "rgb" || colorSpace === "ycbcr") {
|
|
1346
|
+
colorSpace = colorSpace === "rgb" ? "rgba" : "ycck";
|
|
1347
|
+
} else if (colorSpace === "unknown") {
|
|
1348
|
+
colorSpace = "grayscale-alpha";
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
let frames = 1;
|
|
1352
|
+
let animated = isAvis;
|
|
1353
|
+
if (animated) {
|
|
1354
|
+
const iloc = this.findBox(buffer, "iloc", metaSubStart, metaSubEnd);
|
|
1355
|
+
if (iloc) {
|
|
1356
|
+
const version = buffer?.[iloc.pos];
|
|
1357
|
+
const itemCountPos = iloc.pos + (version ? version < 2 ? 4 : 6 : 4);
|
|
1358
|
+
frames = buffer.readUInt16BE(itemCountPos);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1084
1361
|
return {
|
|
1085
1362
|
width,
|
|
1086
1363
|
height,
|
|
1087
|
-
|
|
1364
|
+
format: "avif",
|
|
1365
|
+
frames,
|
|
1366
|
+
animated,
|
|
1367
|
+
hasAlpha: hasAlpha ? true : null,
|
|
1368
|
+
// null if unknown
|
|
1369
|
+
orientation: null,
|
|
1370
|
+
// Can have 'irot' or 'imir' transforms, but rare
|
|
1371
|
+
aspectRatio: width / height,
|
|
1372
|
+
colorSpace,
|
|
1373
|
+
iccProfile,
|
|
1374
|
+
exifDateTimeOriginal: null
|
|
1375
|
+
// Can have 'XMP' box, but parse XMP for date if needed
|
|
1088
1376
|
};
|
|
1089
1377
|
}
|
|
1090
1378
|
throw new Error("Unsupported image format or invalid file");
|
package/dist/fs/index.d.cts
CHANGED
|
@@ -113,12 +113,12 @@ declare class Fs extends MimeService {
|
|
|
113
113
|
fileToBufferAsync: <const T extends string>(path: T) => Promise<Buffer<ArrayBufferLike>>;
|
|
114
114
|
dirContainsDir<const From extends string, const To extends string>(readDir: From, targetDir: To, options?: ReadDirOptions): boolean;
|
|
115
115
|
assetToBuffer<const T extends string>(path: T): Promise<{
|
|
116
|
-
readonly b64encodedData: `data:
|
|
117
|
-
readonly extension: "
|
|
116
|
+
readonly b64encodedData: `data:audio/aac;base64, ${string}` | `data:application/x-abiword;base64, ${string}` | `data:image/aces;base64, ${string}` | `data:image/apng;base64, ${string}` | `data:application/x-freearc;base64, ${string}` | `data:image/avci;base64, ${string}` | `data:image/avif;base64, ${string}` | `data:video/x-msvideo;base64, ${string}` | `data:application/vnd.amazon.ebook;base64, ${string}` | `data:application/octet-stream;base64, ${string}` | `data:multipart/voice-message;base64, ${string}` | `data:image/bmp;base64, ${string}` | `data:application/x-bzip;base64, ${string}` | `data:application/x-bzip2;base64, ${string}` | `data:application/x-cdf;base64, ${string}` | `data:application/node;base64, ${string}` | `data:text/javascript;base64, ${string}` | `data:application/x-csh;base64, ${string}` | `data:text/css;base64, ${string}` | `data:text/csv;base64, ${string}` | `data:application/msword;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64, ${string}` | `data:image/dpx;base64, ${string}` | `data:image/emf;base64, ${string}` | `data:application/vnd.ms-fontobject;base64, ${string}` | `data:application/epub+zip;base64, ${string}` | `data:image/gif;base64, ${string}` | `data:model/gltf-binary;base64, ${string}` | `data:model/gltf+json;base64, ${string}` | `data:application/gzip;base64, ${string}` | `data:application/x-gzip;base64, ${string}` | `data:haptics/hjif;base64, ${string}` | `data:haptics/hmpg;base64, ${string}` | `data:text/html;base64, ${string}` | `data:image/vnd.microsoft.icon;base64, ${string}` | `data:text/calendar;base64, ${string}` | `data:haptics/ivs;base64, ${string}` | `data:application/java-archive;base64, ${string}` | `data:image/jpeg;base64, ${string}` | `data:application/json;base64, ${string}` | `data:application/ld+json;base64, ${string}` | `data:image/ktx;base64, ${string}` | `data:image/ktx2;base64, ${string}` | `data:application/vnd.apple.mpegurl;base64, ${string}` | `data:audio/mp4;base64, ${string}` | `data:video/mp4;base64, ${string}` | `data:text/markdown;base64, ${string}` | `data:application/x-mdx;base64, ${string}` | `data:audio/midi;base64, ${string}` | `data:audio/x-midi;base64, ${string}` | `data:audio/mpeg;base64, ${string}` | `data:video/mpeg;base64, ${string}` | `data:application/vnd.apple.installer+xml;base64, ${string}` | `data:application/x-ndjson;base64, ${string}` | `data:model/obj;base64, ${string}` | `data:text/plain;base64, ${string}` | `data:application/vnd.oasis.opendocument.presentation;base64, ${string}` | `data:application/vnd.oasis.opendocument.spreadsheet;base64, ${string}` | `data:application/vnd.oasis.opendocument.text;base64, ${string}` | `data:audio/ogg;base64, ${string}` | `data:video/ogg;base64, ${string}` | `data:application/ogg;base64, ${string}` | `data:font/otf;base64, ${string}` | `data:image/png;base64, ${string}` | `data:application/pdf;base64, ${string}` | `data:application/x-httpd-php;base64, ${string}` | `data:application/vnd.apple.pkpass;base64, ${string}` | `data:application/vnd.ms-powerpoint;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.presentationml.presentation;base64, ${string}` | `data:text/x-python;base64, ${string}` | `data:application/x-python-code;base64, ${string}` | `data:application/vnd.rar;base64, ${string}` | `data:text/rust;base64, ${string}` | `data:application/rtf;base64, ${string}` | `data:application/x-sh;base64, ${string}` | `data:application/sql;base64, ${string}` | `data:text/event-stream;base64, ${string}` | `data:image/svg+xml;base64, ${string}` | `data:application/x-tar;base64, ${string}` | `data:image/tiff;base64, ${string}` | `data:application/toml;base64, ${string}` | `data:text/typescript;base64, ${string}` | `data:video/mp2t;base64, ${string}` | `data:video/vnd.dlna.mpeg-tts;base64, ${string}` | `data:application/font-sfnt;base64, ${string}` | `data:font/ttf;base64, ${string}` | `data:model/vnd.usdz+zip;base64, ${string}` | `data:application/vnd.visio;base64, ${string}` | `data:text/vtt;base64, ${string}` | `data:application/wasm;base64, ${string}` | `data:audio/wav;base64, ${string}` | `data:video/webm;base64, ${string}` | `data:image/webp;base64, ${string}` | `data:font/woff;base64, ${string}` | `data:font/woff2;base64, ${string}` | `data:application/xhtml+xml;base64, ${string}` | `data:application/vnd.ms-excel;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64, ${string}` | `data:application/xml;base64, ${string}` | `data:application/vnd.mozilla.xul+xml;base64, ${string}` | `data:application/yaml;base64, ${string}` | `data:application/zip;base64, ${string}` | `data:application/x-zip-compressed;base64, ${string}` | `data:video/3gpp;base64, ${string}` | `data:video/3gpp2;base64, ${string}` | `data:application/x-7z-compressed;base64, ${string}`;
|
|
117
|
+
readonly extension: "png" | "jpeg" | "gif" | "bmp" | "webp" | "avif" | "epub" | "ttf" | "gz" | "jar" | "json" | "jsonld" | "doc" | "node" | "js" | "bin" | "obj" | "ogx" | "pdf" | "rtf" | "sql" | "toml" | "azw" | "mpkg" | "m3u8" | "pkpass" | "xul" | "xls" | "eot" | "ppt" | "odp" | "ods" | "odt" | "pptx" | "xlsx" | "docx" | "rar" | "vsd" | "wasm" | "7z" | "abw" | "bz" | "bz2" | "cda" | "csh" | "arc" | "php" | "mdx" | "ndjson" | "pyc" | "sh" | "tar" | "zip" | "xhtml" | "xml" | "yml" | "yaml" | "aac" | "mid" | "m4a" | "mp3" | "opus" | "ogg" | "oga" | "wav" | "midi" | "otf" | "woff" | "woff2" | "hjif" | "hmpg" | "ivs" | "ivt" | "aces" | "apng" | "avci" | "dpx" | "emf" | "jpg" | "ktx" | "ktx2" | "svg" | "tiff" | "tif" | "ico" | "glb" | "gltf" | "usdz" | "ics" | "css" | "csv" | "sse" | "ts" | "rs" | "py" | "txt" | "html" | "htm" | "cjs" | "mjs" | "md" | "vtt" | "3gp" | "3g2" | "mp4" | "m4v" | "mpeg" | "ogv" | "weba" | "avi";
|
|
118
118
|
}>;
|
|
119
119
|
assetToBufferView<const T extends string>(path: T): Promise<{
|
|
120
120
|
readonly b64encodedData: string;
|
|
121
|
-
readonly extension: "
|
|
121
|
+
readonly extension: "png" | "jpeg" | "gif" | "bmp" | "webp" | "avif" | "epub" | "ttf" | "gz" | "jar" | "json" | "jsonld" | "doc" | "node" | "js" | "bin" | "obj" | "ogx" | "pdf" | "rtf" | "sql" | "toml" | "azw" | "mpkg" | "m3u8" | "pkpass" | "xul" | "xls" | "eot" | "ppt" | "odp" | "ods" | "odt" | "pptx" | "xlsx" | "docx" | "rar" | "vsd" | "wasm" | "7z" | "abw" | "bz" | "bz2" | "cda" | "csh" | "arc" | "php" | "mdx" | "ndjson" | "pyc" | "sh" | "tar" | "zip" | "xhtml" | "xml" | "yml" | "yaml" | "aac" | "mid" | "m4a" | "mp3" | "opus" | "ogg" | "oga" | "wav" | "midi" | "otf" | "woff" | "woff2" | "hjif" | "hmpg" | "ivs" | "ivt" | "aces" | "apng" | "avci" | "dpx" | "emf" | "jpg" | "ktx" | "ktx2" | "svg" | "tiff" | "tif" | "ico" | "glb" | "gltf" | "usdz" | "ics" | "css" | "csv" | "sse" | "ts" | "rs" | "py" | "txt" | "html" | "htm" | "cjs" | "mjs" | "md" | "vtt" | "3gp" | "3g2" | "mp4" | "m4v" | "mpeg" | "ogv" | "weba" | "avi" | undefined;
|
|
122
122
|
}>;
|
|
123
123
|
formatHelper<const T extends string>(f: T): string;
|
|
124
124
|
cleanDataUrl<const C extends string>(props: C): string;
|
|
@@ -135,6 +135,10 @@ declare class Fs extends MimeService {
|
|
|
135
135
|
* ✅ 'public/assets/image-1.png'
|
|
136
136
|
*/
|
|
137
137
|
fetchRemoteWriteLocal<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
|
|
138
|
+
parseExif(buffer: Buffer, app1Pos: number, _app1Size: number): {
|
|
139
|
+
orientation: number | null;
|
|
140
|
+
dateTimeOriginal: string | null;
|
|
141
|
+
};
|
|
138
142
|
/**
|
|
139
143
|
*
|
|
140
144
|
* @param inputUrl remote url to fetch data from
|
|
@@ -153,30 +157,78 @@ declare class Fs extends MimeService {
|
|
|
153
157
|
*/
|
|
154
158
|
fetchRemoteWriteLocalLargeFiles<const I extends string, const O extends string>(inputUrl: I, outputPathI: O, useDetectedExtension?: boolean): Promise<void>;
|
|
155
159
|
private findBox;
|
|
156
|
-
|
|
160
|
+
getImageSpecs(filePath: string): Promise<{
|
|
157
161
|
width: number;
|
|
158
162
|
height: number;
|
|
159
|
-
|
|
163
|
+
format: "png";
|
|
164
|
+
frames: number;
|
|
165
|
+
animated: boolean;
|
|
166
|
+
hasAlpha: boolean;
|
|
167
|
+
orientation: null;
|
|
168
|
+
aspectRatio: number;
|
|
169
|
+
colorSpace: "unknown" | "rgb" | "rgba" | "grayscale" | "grayscale-alpha" | "indexed";
|
|
170
|
+
iccProfile: string | null;
|
|
171
|
+
exifDateTimeOriginal: string | null;
|
|
160
172
|
} | {
|
|
161
173
|
width: number;
|
|
162
174
|
height: number;
|
|
163
|
-
|
|
175
|
+
format: "jpeg";
|
|
176
|
+
frames: number;
|
|
177
|
+
animated: false;
|
|
178
|
+
hasAlpha: false;
|
|
179
|
+
orientation: number | null;
|
|
180
|
+
aspectRatio: number;
|
|
181
|
+
colorSpace: "unknown" | "grayscale" | "ycbcr" | "ycck";
|
|
182
|
+
iccProfile: string | null;
|
|
183
|
+
exifDateTimeOriginal: string | null;
|
|
164
184
|
} | {
|
|
165
185
|
width: number;
|
|
166
186
|
height: number;
|
|
167
|
-
|
|
187
|
+
format: "gif";
|
|
188
|
+
frames: number;
|
|
189
|
+
animated: boolean;
|
|
190
|
+
hasAlpha: null;
|
|
191
|
+
orientation: null;
|
|
192
|
+
aspectRatio: number;
|
|
193
|
+
colorSpace: "indexed";
|
|
194
|
+
iccProfile: null;
|
|
195
|
+
exifDateTimeOriginal: null;
|
|
168
196
|
} | {
|
|
169
197
|
width: number;
|
|
170
198
|
height: number;
|
|
171
|
-
|
|
199
|
+
format: "bmp";
|
|
200
|
+
frames: number;
|
|
201
|
+
animated: false;
|
|
202
|
+
hasAlpha: null;
|
|
203
|
+
orientation: number;
|
|
204
|
+
aspectRatio: number;
|
|
205
|
+
colorSpace: "rgb" | "indexed";
|
|
206
|
+
iccProfile: null;
|
|
207
|
+
exifDateTimeOriginal: null;
|
|
172
208
|
} | {
|
|
173
209
|
width: number;
|
|
174
210
|
height: number;
|
|
175
|
-
|
|
211
|
+
format: "webp";
|
|
212
|
+
frames: number;
|
|
213
|
+
animated: boolean;
|
|
214
|
+
hasAlpha: boolean;
|
|
215
|
+
orientation: null;
|
|
216
|
+
aspectRatio: number;
|
|
217
|
+
colorSpace: "unknown" | "rgb" | "rgba";
|
|
218
|
+
iccProfile: string | null;
|
|
219
|
+
exifDateTimeOriginal: null;
|
|
176
220
|
} | {
|
|
177
221
|
width: number;
|
|
178
222
|
height: number;
|
|
179
|
-
|
|
223
|
+
format: "avif";
|
|
224
|
+
frames: number;
|
|
225
|
+
animated: boolean;
|
|
226
|
+
hasAlpha: true | null;
|
|
227
|
+
orientation: null;
|
|
228
|
+
aspectRatio: number;
|
|
229
|
+
colorSpace: "unknown" | "rgb" | "rgba" | "grayscale-alpha" | "ycbcr" | "ycck";
|
|
230
|
+
iccProfile: string | null;
|
|
231
|
+
exifDateTimeOriginal: null;
|
|
180
232
|
}>;
|
|
181
233
|
/**
|
|
182
234
|
*
|