@d0paminedriven/fs 2.0.0 → 3.0.0
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/dist/{chunk-J3NUWUIN.js → chunk-SPP3NFBL.js} +38 -1
- package/dist/fs/index.cjs +37 -0
- package/dist/fs/index.d.cts +1 -0
- package/dist/fs/index.d.ts +1 -0
- package/dist/fs/index.js +1 -1
- package/dist/index.cjs +37 -0
- package/dist/index.js +1 -1
- package/package.json +3 -3
|
@@ -623,6 +623,43 @@ var Fs = class {
|
|
|
623
623
|
return console.error(err);
|
|
624
624
|
}
|
|
625
625
|
}
|
|
626
|
+
async fetchRemoteWriteLocalLargeFiles(inputUrl, outputPath, useDetectedExtension = true) {
|
|
627
|
+
const MAX_SAFE_IN_MEMORY_MB = 100;
|
|
628
|
+
try {
|
|
629
|
+
const head = await fetch(inputUrl, { method: "HEAD" });
|
|
630
|
+
const contentLength = head.headers.get("content-length");
|
|
631
|
+
const fileSizeMb = contentLength ? parseInt(contentLength, 10) / (1024 * 1024) : null;
|
|
632
|
+
const formattedPath = useDetectedExtension ? `${outputPath}.${this.assetType(inputUrl)}` : outputPath;
|
|
633
|
+
this.generateDirIfDNE(this.pathHandler(formattedPath), {
|
|
634
|
+
recursive: true
|
|
635
|
+
});
|
|
636
|
+
if (fileSizeMb !== null && fileSizeMb > MAX_SAFE_IN_MEMORY_MB) {
|
|
637
|
+
const res = await fetch(inputUrl);
|
|
638
|
+
if (!res.ok || !res.body) {
|
|
639
|
+
throw new Error(`Failed to fetch asset: ${res.statusText}`);
|
|
640
|
+
}
|
|
641
|
+
const writeStream = fsSync.createWriteStream(
|
|
642
|
+
relative(this.cwd ?? process.cwd(), formattedPath)
|
|
643
|
+
);
|
|
644
|
+
const reader = res.body.getReader();
|
|
645
|
+
const pump = /* @__PURE__ */ __name(async () => {
|
|
646
|
+
while (true) {
|
|
647
|
+
const { done, value } = await reader.read();
|
|
648
|
+
if (done) break;
|
|
649
|
+
writeStream.write(value);
|
|
650
|
+
}
|
|
651
|
+
writeStream.end();
|
|
652
|
+
}, "pump");
|
|
653
|
+
await pump();
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
const result = await this.assetToBufferView(inputUrl);
|
|
657
|
+
const cleanData = this.cleanDataUrl(result.b64encodedData);
|
|
658
|
+
this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
|
|
659
|
+
} catch (err) {
|
|
660
|
+
console.error(`[fetchRemoteWriteLocal error]:`, err);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
626
663
|
// USE fluent-ffmpeg for video/animated image transforms (apng, etc)
|
|
627
664
|
// https://www.npmjs.com/package/fluent-ffmpeg
|
|
628
665
|
// https://www.npmjs.com/package/@types/fluent-ffmpeg
|
|
@@ -688,4 +725,4 @@ var Fs = class {
|
|
|
688
725
|
export {
|
|
689
726
|
Fs
|
|
690
727
|
};
|
|
691
|
-
//# sourceMappingURL=chunk-
|
|
728
|
+
//# sourceMappingURL=chunk-SPP3NFBL.js.map
|
package/dist/fs/index.cjs
CHANGED
|
@@ -664,6 +664,43 @@ var Fs = class {
|
|
|
664
664
|
return console.error(err);
|
|
665
665
|
}
|
|
666
666
|
}
|
|
667
|
+
async fetchRemoteWriteLocalLargeFiles(inputUrl, outputPath, useDetectedExtension = true) {
|
|
668
|
+
const MAX_SAFE_IN_MEMORY_MB = 100;
|
|
669
|
+
try {
|
|
670
|
+
const head = await fetch(inputUrl, { method: "HEAD" });
|
|
671
|
+
const contentLength = head.headers.get("content-length");
|
|
672
|
+
const fileSizeMb = contentLength ? parseInt(contentLength, 10) / (1024 * 1024) : null;
|
|
673
|
+
const formattedPath = useDetectedExtension ? `${outputPath}.${this.assetType(inputUrl)}` : outputPath;
|
|
674
|
+
this.generateDirIfDNE(this.pathHandler(formattedPath), {
|
|
675
|
+
recursive: true
|
|
676
|
+
});
|
|
677
|
+
if (fileSizeMb !== null && fileSizeMb > MAX_SAFE_IN_MEMORY_MB) {
|
|
678
|
+
const res = await fetch(inputUrl);
|
|
679
|
+
if (!res.ok || !res.body) {
|
|
680
|
+
throw new Error(`Failed to fetch asset: ${res.statusText}`);
|
|
681
|
+
}
|
|
682
|
+
const writeStream = import_fs.default.createWriteStream(
|
|
683
|
+
(0, import_path.relative)(this.cwd ?? process.cwd(), formattedPath)
|
|
684
|
+
);
|
|
685
|
+
const reader = res.body.getReader();
|
|
686
|
+
const pump = /* @__PURE__ */ __name(async () => {
|
|
687
|
+
while (true) {
|
|
688
|
+
const { done, value } = await reader.read();
|
|
689
|
+
if (done) break;
|
|
690
|
+
writeStream.write(value);
|
|
691
|
+
}
|
|
692
|
+
writeStream.end();
|
|
693
|
+
}, "pump");
|
|
694
|
+
await pump();
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
const result = await this.assetToBufferView(inputUrl);
|
|
698
|
+
const cleanData = this.cleanDataUrl(result.b64encodedData);
|
|
699
|
+
this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
|
|
700
|
+
} catch (err) {
|
|
701
|
+
console.error(`[fetchRemoteWriteLocal error]:`, err);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
667
704
|
// USE fluent-ffmpeg for video/animated image transforms (apng, etc)
|
|
668
705
|
// https://www.npmjs.com/package/fluent-ffmpeg
|
|
669
706
|
// https://www.npmjs.com/package/@types/fluent-ffmpeg
|
package/dist/fs/index.d.cts
CHANGED
|
@@ -418,6 +418,7 @@ declare class Fs {
|
|
|
418
418
|
* ✅ 'public/assets/image-1.png'
|
|
419
419
|
*/
|
|
420
420
|
fetchRemoteWriteLocal<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
|
|
421
|
+
fetchRemoteWriteLocalLargeFiles<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
|
|
421
422
|
imageTransform<const F extends "webp" | "avif" | "jpg" | "png" | "tif" | "tiff" | "jp2" | "jpeg">({ format, target, quality, tint, resize }: {
|
|
422
423
|
format: F;
|
|
423
424
|
target: Buffer<ArrayBuffer>;
|
package/dist/fs/index.d.ts
CHANGED
|
@@ -418,6 +418,7 @@ declare class Fs {
|
|
|
418
418
|
* ✅ 'public/assets/image-1.png'
|
|
419
419
|
*/
|
|
420
420
|
fetchRemoteWriteLocal<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
|
|
421
|
+
fetchRemoteWriteLocalLargeFiles<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
|
|
421
422
|
imageTransform<const F extends "webp" | "avif" | "jpg" | "png" | "tif" | "tiff" | "jp2" | "jpeg">({ format, target, quality, tint, resize }: {
|
|
422
423
|
format: F;
|
|
423
424
|
target: Buffer<ArrayBuffer>;
|
package/dist/fs/index.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -667,6 +667,43 @@ var Fs = class {
|
|
|
667
667
|
return console.error(err);
|
|
668
668
|
}
|
|
669
669
|
}
|
|
670
|
+
async fetchRemoteWriteLocalLargeFiles(inputUrl, outputPath, useDetectedExtension = true) {
|
|
671
|
+
const MAX_SAFE_IN_MEMORY_MB = 100;
|
|
672
|
+
try {
|
|
673
|
+
const head = await fetch(inputUrl, { method: "HEAD" });
|
|
674
|
+
const contentLength = head.headers.get("content-length");
|
|
675
|
+
const fileSizeMb = contentLength ? parseInt(contentLength, 10) / (1024 * 1024) : null;
|
|
676
|
+
const formattedPath = useDetectedExtension ? `${outputPath}.${this.assetType(inputUrl)}` : outputPath;
|
|
677
|
+
this.generateDirIfDNE(this.pathHandler(formattedPath), {
|
|
678
|
+
recursive: true
|
|
679
|
+
});
|
|
680
|
+
if (fileSizeMb !== null && fileSizeMb > MAX_SAFE_IN_MEMORY_MB) {
|
|
681
|
+
const res = await fetch(inputUrl);
|
|
682
|
+
if (!res.ok || !res.body) {
|
|
683
|
+
throw new Error(`Failed to fetch asset: ${res.statusText}`);
|
|
684
|
+
}
|
|
685
|
+
const writeStream = import_fs.default.createWriteStream(
|
|
686
|
+
(0, import_path.relative)(this.cwd ?? process.cwd(), formattedPath)
|
|
687
|
+
);
|
|
688
|
+
const reader = res.body.getReader();
|
|
689
|
+
const pump = /* @__PURE__ */ __name(async () => {
|
|
690
|
+
while (true) {
|
|
691
|
+
const { done, value } = await reader.read();
|
|
692
|
+
if (done) break;
|
|
693
|
+
writeStream.write(value);
|
|
694
|
+
}
|
|
695
|
+
writeStream.end();
|
|
696
|
+
}, "pump");
|
|
697
|
+
await pump();
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
const result = await this.assetToBufferView(inputUrl);
|
|
701
|
+
const cleanData = this.cleanDataUrl(result.b64encodedData);
|
|
702
|
+
this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
|
|
703
|
+
} catch (err) {
|
|
704
|
+
console.error(`[fetchRemoteWriteLocal error]:`, err);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
670
707
|
// USE fluent-ffmpeg for video/animated image transforms (apng, etc)
|
|
671
708
|
// https://www.npmjs.com/package/fluent-ffmpeg
|
|
672
709
|
// https://www.npmjs.com/package/@types/fluent-ffmpeg
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d0paminedriven/fs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "convenient fs helpers",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
"tsx": "latest",
|
|
56
56
|
"typescript": "latest",
|
|
57
57
|
"typescript-eslint": "latest",
|
|
58
|
+
"@portfolio/eslint-config": "1.0.0",
|
|
58
59
|
"@portfolio/prettier-config": "0.1.0",
|
|
59
|
-
"@portfolio/tsconfig": "0.1.0"
|
|
60
|
-
"@portfolio/eslint-config": "1.0.0"
|
|
60
|
+
"@portfolio/tsconfig": "0.1.0"
|
|
61
61
|
},
|
|
62
62
|
"prettier": "@portfolio/prettier-config",
|
|
63
63
|
"scripts": {
|