@d0paminedriven/fs 10.1.0 → 11.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/docs/index.d.ts +119 -0
- package/dist/docs/index.js +1027 -0
- package/dist/extract/client.d.ts +54 -0
- package/dist/extract/client.js +118 -0
- package/dist/extract/index.d.ts +69 -0
- package/dist/extract/index.js +622 -0
- package/dist/fs/index.d.ts +19 -55
- package/dist/fs/index.js +88 -19
- package/dist/fs-atomic/index.d.ts +28 -36
- package/dist/fs-atomic/index.js +88 -13
- package/dist/fs-base/index.d.ts +105 -111
- package/dist/fs-base/index.js +188 -12
- package/dist/fs-core/index.d.ts +20 -24
- package/dist/fs-core/index.js +44 -16
- package/dist/fs-fetch/index.d.ts +48 -62
- package/dist/fs-fetch/index.js +146 -18
- package/dist/fs-size/index.d.ts +16 -28
- package/dist/fs-size/index.js +64 -15
- package/dist/fs-tmp/index.d.ts +179 -192
- package/dist/fs-tmp/index.js +321 -17
- package/dist/images/index.d.ts +447 -0
- package/dist/images/index.js +899 -0
- package/dist/images/workup.d.ts +30 -0
- package/dist/images/workup.js +317 -0
- package/dist/index.d.ts +20 -22
- package/dist/index.js +20 -64
- package/dist/ld/index.d.ts +15 -13
- package/dist/ld/index.js +56 -6
- package/dist/mime/index.d.ts +299 -294
- package/dist/mime/index.js +348 -13
- package/dist/mixins/index.d.ts +34 -0
- package/dist/mixins/index.js +54 -0
- package/dist/types/index.d.ts +279 -215
- package/dist/types/index.js +11 -6
- package/dist/types/stream.d.ts +6 -4
- package/dist/types/stream.js +1 -1
- package/dist/url/index.d.ts +15 -18
- package/dist/url/index.js +21 -8
- package/dist/utils/index.d.ts +19 -23
- package/dist/utils/index.js +82 -7
- package/package.json +33 -13
- package/dist/chunk-4D2YBCI6.js +0 -163
- package/dist/chunk-5CACVZVF.js +0 -386
- package/dist/chunk-5H6GE5AO.js +0 -14
- package/dist/chunk-7QVYU63E.js +0 -7
- package/dist/chunk-DNR5ZI2T.js +0 -75
- package/dist/chunk-JZ6JNZZ6.js +0 -77
- package/dist/chunk-L2QMQOEJ.js +0 -366
- package/dist/chunk-NJHN5OE3.js +0 -33
- package/dist/chunk-OHKRQJZH.js +0 -82
- package/dist/chunk-OT5JEQKW.js +0 -139
- package/dist/chunk-PATMSIQK.js +0 -367
- package/dist/chunk-PB5A7ZFD.js +0 -79
- package/dist/chunk-VDKUXJE7.js +0 -240
- package/dist/chunk-Y5QWE4EG.js +0 -1335
- package/dist/chunk-YRCJWFZD.js +0 -107
- package/dist/image/index.d.ts +0 -182
- package/dist/image/index.js +0 -13
- package/dist/image/workup.d.ts +0 -40
- package/dist/image/workup.js +0 -12
package/dist/url/index.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { UtilsService } from
|
|
2
|
-
import '../types/index.js';
|
|
3
|
-
import 'stream';
|
|
4
|
-
import 'fs';
|
|
5
|
-
import '../ld/index.js';
|
|
6
|
-
import '@d0paminedriven/metadata';
|
|
1
|
+
import { UtilsService } from "../utils/index.js";
|
|
7
2
|
|
|
3
|
+
//#region src/url/index.d.ts
|
|
8
4
|
type HandleQueryParamsOrHash<T> = T extends `${infer X}?${string}` ? X : T extends `${infer X}#${string}` ? X : T;
|
|
9
5
|
type SplitForwardSlash<S extends string> = S extends `${infer First}/${infer Rest}` ? [First, ...SplitForwardSlash<Rest>] : S extends "" ? [] : [S];
|
|
10
6
|
type LastSegment<T extends unknown[]> = T extends [...infer _, infer L] ? L : never;
|
|
@@ -20,16 +16,17 @@ type InferExtensionIfPresent<L> = L extends `${string}.${infer F}` ? F : "NO_EXT
|
|
|
20
16
|
*/
|
|
21
17
|
type UrlFileExt<S extends string> = InferExtensionIfPresent<LastSegment<SplitForwardSlash<HandleQueryParamsOrHash<S>>>>;
|
|
22
18
|
declare class UrlService extends UtilsService {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
19
|
+
private URL_REGEX;
|
|
20
|
+
parseUrl(url: string): {
|
|
21
|
+
href: string;
|
|
22
|
+
protocol: string;
|
|
23
|
+
baseUrl: string;
|
|
24
|
+
host: string;
|
|
25
|
+
pathname: string;
|
|
26
|
+
search: string;
|
|
27
|
+
hash: string;
|
|
28
|
+
} | null;
|
|
33
29
|
}
|
|
34
|
-
|
|
35
|
-
export {
|
|
30
|
+
//#endregion
|
|
31
|
+
export { HandleQueryParamsOrHash, InferExtensionIfPresent, LastSegment, SplitForwardSlash, UrlFileExt, UrlService };
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/url/index.js
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { UtilsService } from "../utils/index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/url/index.ts
|
|
4
|
+
var UrlService = class extends UtilsService {
|
|
5
|
+
URL_REGEX = /^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
|
|
6
|
+
parseUrl(url) {
|
|
7
|
+
const parsed = this.URL_REGEX.exec(url);
|
|
8
|
+
if (parsed) return {
|
|
9
|
+
href: parsed[0],
|
|
10
|
+
protocol: parsed[1] ?? "",
|
|
11
|
+
baseUrl: `${parsed[1]}${parsed[3]}`,
|
|
12
|
+
host: parsed[4] ?? "",
|
|
13
|
+
pathname: parsed[5] ?? "",
|
|
14
|
+
search: parsed[6] ?? "",
|
|
15
|
+
hash: parsed[8] ?? ""
|
|
16
|
+
};
|
|
17
|
+
else return null;
|
|
18
|
+
}
|
|
9
19
|
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { UrlService };
|
|
10
23
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
import { RemoveFields
|
|
2
|
-
import { LevenshteinDistance } from
|
|
3
|
-
import 'stream';
|
|
4
|
-
import 'fs';
|
|
5
|
-
import '@d0paminedriven/metadata';
|
|
1
|
+
import { RemoveFields } from "../types/index.js";
|
|
2
|
+
import { LevenshteinDistance } from "../ld/index.js";
|
|
6
3
|
|
|
4
|
+
//#region src/utils/index.d.ts
|
|
7
5
|
declare class UtilsService extends LevenshteinDistance {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
range(from: number, to: number): number[];
|
|
23
|
-
isPrimeNumber: <const T extends number>(n: T) => boolean;
|
|
24
|
-
acceptor: (num: number) => number[];
|
|
6
|
+
constructor();
|
|
7
|
+
chunkArray<T extends number>(arr: string[], maxChunkLength: T): string[][];
|
|
8
|
+
b64ToBlob<const T extends string>(b64Data: T): Blob;
|
|
9
|
+
arrToArrOfArrs: <const T>(arr: T[], int?: number, agg?: T[][]) => T[][];
|
|
10
|
+
extractTuple<const T extends Record<string | number | symbol, unknown> | Enumerator<unknown>, const V extends keyof T>(obj: T, props: V): readonly [V, T[V]];
|
|
11
|
+
sort<const S extends Record<string | number | symbol, unknown> | Enumerator<unknown>, const K extends "ASC" | "DESC" | undefined>(obj: S, order?: K): S;
|
|
12
|
+
excludeTargeted: <const T extends Enumerator<unknown> | Record<string | number | symbol, unknown>, const V extends keyof T, const S extends "ASC" | "DESC" | undefined>(obj: T, props: V[], sort?: S | undefined) => RemoveFields<T, V>;
|
|
13
|
+
includeTargeted: <const T extends Enumerator<unknown> | Record<string | number | symbol, unknown>, const V extends keyof T, const S extends "ASC" | "DESC" | undefined>(obj: T, props: V[], sort?: S | undefined) => Pick<T, V>;
|
|
14
|
+
countsSorter: <const T extends object>(counter: T, keySort?: "ASC" | "DESC", valSort?: "ASC" | "DESC") => {
|
|
15
|
+
[k: string]: any;
|
|
16
|
+
};
|
|
17
|
+
range(from: number, to: number): number[];
|
|
18
|
+
isPrimeNumber: <const T extends number>(n: T) => boolean;
|
|
19
|
+
acceptor: (num: number) => number[];
|
|
25
20
|
}
|
|
26
|
-
|
|
21
|
+
//#endregion
|
|
27
22
|
export { UtilsService };
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/utils/index.js
CHANGED
|
@@ -1,9 +1,84 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { LevenshteinDistance } from "../ld/index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/index.ts
|
|
4
|
+
var UtilsService = class extends LevenshteinDistance {
|
|
5
|
+
constructor() {
|
|
6
|
+
super();
|
|
7
|
+
}
|
|
8
|
+
chunkArray(arr, maxChunkLength) {
|
|
9
|
+
const chunks = Array.of();
|
|
10
|
+
let currentChunkLength = 0;
|
|
11
|
+
let currentChunk = Array.of();
|
|
12
|
+
for (const [index, val] of arr.entries()) {
|
|
13
|
+
if (val.length + currentChunkLength >= maxChunkLength) {
|
|
14
|
+
if (currentChunk.length) chunks.push(currentChunk);
|
|
15
|
+
currentChunkLength = val.length;
|
|
16
|
+
currentChunk = [val];
|
|
17
|
+
} else {
|
|
18
|
+
currentChunk.push(val);
|
|
19
|
+
currentChunkLength += val.length + 1;
|
|
20
|
+
}
|
|
21
|
+
if (arr.length === index + 1) chunks.push(currentChunk);
|
|
22
|
+
}
|
|
23
|
+
return chunks.length ? chunks : [arr];
|
|
24
|
+
}
|
|
25
|
+
b64ToBlob(b64Data) {
|
|
26
|
+
{
|
|
27
|
+
const sliceSize = 512;
|
|
28
|
+
const typeMatch = /^data:((?:image|application|haptics|video|text|font|model|audio|multipart)\/[A-Za-z0-9+-.]+(?:;[^,]+)*);base64,(.+)$/i.exec(b64Data);
|
|
29
|
+
if (!typeMatch) throw new Error(`${b64Data} is not a valid data Url`);
|
|
30
|
+
const type = typeMatch[1];
|
|
31
|
+
const base64Data = typeMatch?.[2] ?? "";
|
|
32
|
+
const byteCharacters = Buffer.from(base64Data, "base64").toString("binary");
|
|
33
|
+
const byteArrays = Array.of();
|
|
34
|
+
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
|
|
35
|
+
const slice = byteCharacters.slice(offset, offset + sliceSize);
|
|
36
|
+
const byteNumbers = new Array(slice.length);
|
|
37
|
+
for (let i = 0; i < slice.length; i++) byteNumbers[i] = slice.charCodeAt(i);
|
|
38
|
+
const byteArray = new Uint8Array(byteNumbers);
|
|
39
|
+
byteArrays.push(byteArray);
|
|
40
|
+
}
|
|
41
|
+
return new Blob(byteArrays, { type });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
arrToArrOfArrs = (arr, int = 10, agg = Array.of()) => {
|
|
45
|
+
for (let i = 0; i < arr.length; i++) agg.push(arr.slice(i, i + int));
|
|
46
|
+
return agg;
|
|
47
|
+
};
|
|
48
|
+
extractTuple(obj, props) {
|
|
49
|
+
return [props, obj[props]];
|
|
50
|
+
}
|
|
51
|
+
sort(obj, order) {
|
|
52
|
+
return Object.fromEntries(Object.entries(obj).sort(([a, _aa], [b, _bb]) => order === "DESC" ? b.localeCompare(a) - a.localeCompare(b) : a.localeCompare(b) - b.localeCompare(a)));
|
|
53
|
+
}
|
|
54
|
+
excludeTargeted = (obj, props, sort) => {
|
|
55
|
+
const resolve = Object.fromEntries(Object.entries(obj).map(([key, val]) => {
|
|
56
|
+
if (props.includes(key)) return ["omit", "omit"];
|
|
57
|
+
else return [key, val];
|
|
58
|
+
}).filter(([t, _v]) => /omit/.test(t) === false));
|
|
59
|
+
return typeof sort !== "undefined" ? this.sort(resolve, sort) : resolve;
|
|
60
|
+
};
|
|
61
|
+
includeTargeted = (obj, props, sort) => {
|
|
62
|
+
const resolve = Object.fromEntries(props.map((val) => this.extractTuple(obj, val)));
|
|
63
|
+
return typeof sort !== "undefined" ? this.sort(resolve, sort) : resolve;
|
|
64
|
+
};
|
|
65
|
+
countsSorter = (counter, keySort = "ASC", valSort = "DESC") => Object.fromEntries(Array.from(Object.entries(counter)).sort(([aStr, _aNum], [bStr, _bNum]) => keySort === "DESC" ? bStr.localeCompare(aStr) - aStr.localeCompare(bStr) : aStr.localeCompare(bStr) - bStr.localeCompare(aStr)).sort(([aStr, aNum], [bStr, bNum]) => {
|
|
66
|
+
if (typeof (aNum && bNum) === "number") return valSort === "ASC" ? aNum - bNum : bNum - aNum;
|
|
67
|
+
else if (typeof (aNum && bNum) === "string") return valSort === "ASC" ? aStr.localeCompare(bStr) - bStr.localeCompare(aStr) : bStr.localeCompare(aStr) - aStr.localeCompare(bStr);
|
|
68
|
+
else throw new Error("only Record<string, string> and Record<string,number> types supported");
|
|
69
|
+
}));
|
|
70
|
+
range(from, to) {
|
|
71
|
+
const values = Array.of();
|
|
72
|
+
for (let i = from; i < to; i++) values.push(i);
|
|
73
|
+
return values;
|
|
74
|
+
}
|
|
75
|
+
isPrimeNumber = (n) => {
|
|
76
|
+
for (let i = 2; n > i; i++) if (n % i === 0) return false;
|
|
77
|
+
return n > 1;
|
|
78
|
+
};
|
|
79
|
+
acceptor = (num) => [...Array(num !== 0 ? num : this.range(num = -101, num = 101)).keys()].reverse().filter(this.isPrimeNumber);
|
|
8
80
|
};
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
export { UtilsService };
|
|
9
84
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d0paminedriven/fs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"homepage": "https://github.com/DopamineDriven/d0paminedriven/blob/master/packages/fs/README.md",
|
|
5
5
|
"author": "Andrew Ross",
|
|
6
6
|
"description": "convenient fs helpers",
|
|
@@ -19,6 +19,20 @@
|
|
|
19
19
|
"dist/*.d.ts",
|
|
20
20
|
"dist/*/index.d.ts"
|
|
21
21
|
],
|
|
22
|
+
"images": [
|
|
23
|
+
"dist/images/index.d.ts",
|
|
24
|
+
"dist/images/workup.d.ts"
|
|
25
|
+
],
|
|
26
|
+
"docs": [
|
|
27
|
+
"dist/docs/index.d.ts"
|
|
28
|
+
],
|
|
29
|
+
"extract": [
|
|
30
|
+
"dist/extract/index.d.ts",
|
|
31
|
+
"dist/extract/client.d.ts"
|
|
32
|
+
],
|
|
33
|
+
"mixins": [
|
|
34
|
+
"dist/mixins/index.d.ts"
|
|
35
|
+
],
|
|
22
36
|
"fs": [
|
|
23
37
|
"dist/fs/index.d.ts"
|
|
24
38
|
],
|
|
@@ -77,6 +91,12 @@
|
|
|
77
91
|
"exports": {
|
|
78
92
|
".": "./dist/index.js",
|
|
79
93
|
"./*": "./dist/*.js",
|
|
94
|
+
"./docs": "./dist/docs/index.js",
|
|
95
|
+
"./extract": "./dist/extract/index.js",
|
|
96
|
+
"./extract/client": "./dist/extract/client.js",
|
|
97
|
+
"./images": "./dist/images/index.js",
|
|
98
|
+
"./images/workup": "./dist/images/workup.js",
|
|
99
|
+
"./mixins": "./dist/mixins/index.js",
|
|
80
100
|
"./fs": "./dist/fs/index.js",
|
|
81
101
|
"./fs-atomic": "./dist/fs-atomic/index.js",
|
|
82
102
|
"./fs-base": "./dist/fs-base/index.js",
|
|
@@ -94,36 +114,36 @@
|
|
|
94
114
|
"./utils": "./dist/utils/index.js"
|
|
95
115
|
},
|
|
96
116
|
"dependencies": {
|
|
97
|
-
"@d0paminedriven/metadata": "^4.0.1",
|
|
98
117
|
"dotenv": "^17.2.3",
|
|
99
118
|
"dotenv-expand": "^12.0.3",
|
|
100
|
-
"fflate": "^0.8.2"
|
|
101
|
-
"sharp": "^0.34.5"
|
|
119
|
+
"fflate": "^0.8.2"
|
|
102
120
|
},
|
|
103
121
|
"devDependencies": {
|
|
104
122
|
"@types/node": "^24.10.1",
|
|
105
|
-
"
|
|
123
|
+
"@typescript/native-preview": "7.0.0-dev.20251206.1",
|
|
124
|
+
"chokidar": "^5.0.0",
|
|
106
125
|
"dotenv-cli": "^11.0.0",
|
|
107
126
|
"eslint": "^9.39.1",
|
|
108
127
|
"jiti": "^2.6.1",
|
|
109
|
-
"prettier": "^3.
|
|
128
|
+
"prettier": "^3.7.4",
|
|
110
129
|
"terser": "^5.44.1",
|
|
111
|
-
"tsdown": "^0.
|
|
130
|
+
"tsdown": "^0.17.0",
|
|
112
131
|
"tslib": "^2.8.1",
|
|
113
|
-
"
|
|
114
|
-
"tsx": "^4.20.6",
|
|
132
|
+
"tsx": "^4.21.0",
|
|
115
133
|
"typescript": "^5.9.3",
|
|
116
134
|
"typescript-eslint": "^8.47.0",
|
|
117
|
-
"@d0paminedriven/
|
|
135
|
+
"@d0paminedriven/eslint-config": "0.1.0",
|
|
118
136
|
"@d0paminedriven/tsconfig": "0.1.0",
|
|
119
|
-
"@d0paminedriven/
|
|
137
|
+
"@d0paminedriven/prettier-config": "0.1.0"
|
|
120
138
|
},
|
|
121
139
|
"prettier": "@d0paminedriven/prettier-config",
|
|
122
140
|
"scripts": {
|
|
123
|
-
"build": "
|
|
141
|
+
"build": "tsdown",
|
|
124
142
|
"dev": "pnpm build",
|
|
125
143
|
"lint": "eslint",
|
|
126
144
|
"clean": "git clean -xdf .turbo dist node_modules",
|
|
127
|
-
"fix": "npm pkg fix"
|
|
145
|
+
"fix": "npm pkg fix",
|
|
146
|
+
"test": "node --test --import tsx --test-reporter spec",
|
|
147
|
+
"pretest": "tsx src/test/output-local.ts"
|
|
128
148
|
}
|
|
129
149
|
}
|
package/dist/chunk-4D2YBCI6.js
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FsTmp
|
|
3
|
-
} from "./chunk-PATMSIQK.js";
|
|
4
|
-
import {
|
|
5
|
-
__name
|
|
6
|
-
} from "./chunk-7QVYU63E.js";
|
|
7
|
-
|
|
8
|
-
// src/fs-fetch/index.ts
|
|
9
|
-
import fsSync from "fs";
|
|
10
|
-
import { relative } from "path";
|
|
11
|
-
var FsFetch = class extends FsTmp {
|
|
12
|
-
constructor(cwd) {
|
|
13
|
-
super(cwd ??= process.cwd());
|
|
14
|
-
this.cwd = cwd;
|
|
15
|
-
}
|
|
16
|
-
static {
|
|
17
|
-
__name(this, "FsFetch");
|
|
18
|
-
}
|
|
19
|
-
async assetToBuffer(path) {
|
|
20
|
-
const [fetcher] = await Promise.all([
|
|
21
|
-
fetch(path).then((t) => t.arrayBuffer())
|
|
22
|
-
]);
|
|
23
|
-
const mime = this.getMimeTypeForPath(path);
|
|
24
|
-
const b64encodedData = `data:${mime};base64, ${Buffer.from(fetcher).toString("base64")}`;
|
|
25
|
-
const extension = this.assetType(path) ?? "txt";
|
|
26
|
-
return {
|
|
27
|
-
b64encodedData,
|
|
28
|
-
extension
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
async assetToBufferView(path) {
|
|
32
|
-
const response = await fetch(path, { method: "GET" });
|
|
33
|
-
if (!response.ok) {
|
|
34
|
-
throw new Error(`Failed to fetch asset: ${response.statusText}`);
|
|
35
|
-
}
|
|
36
|
-
const reader = response.body?.getReader();
|
|
37
|
-
if (reader) {
|
|
38
|
-
const chunks = Array.of();
|
|
39
|
-
while (true) {
|
|
40
|
-
const { done, value } = await reader.read();
|
|
41
|
-
if (done) break;
|
|
42
|
-
if (value) chunks.push(value);
|
|
43
|
-
}
|
|
44
|
-
const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
45
|
-
const completeBuffer = new Uint8Array(totalLength);
|
|
46
|
-
let offset = 0;
|
|
47
|
-
for (const chunk of chunks) {
|
|
48
|
-
completeBuffer.set(chunk, offset);
|
|
49
|
-
offset += chunk.length;
|
|
50
|
-
}
|
|
51
|
-
const mime = this.getMimeTypeForPath(path);
|
|
52
|
-
const b64encodedData = `data:${mime};base64, ${Buffer.from(completeBuffer).toString("base64")}`;
|
|
53
|
-
const extension = this.assetType(path);
|
|
54
|
-
return { b64encodedData, extension };
|
|
55
|
-
} else {
|
|
56
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
57
|
-
const mime = this.getMimeTypeForPath(path);
|
|
58
|
-
const b64encodedData = `data:${mime};base64, ${Buffer.from(arrayBuffer).toString("base64")}`;
|
|
59
|
-
const extension = this.assetType(path);
|
|
60
|
-
return { b64encodedData, extension };
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
*
|
|
65
|
-
* @param inputUrl remote url to fetch data from
|
|
66
|
-
* @param outputPath desired output path relative to the cwd
|
|
67
|
-
* @param useDetectedExtension optional, defaults to true
|
|
68
|
-
*
|
|
69
|
-
* if `useDetectedExtension` is false you must include the file extension in your output path →
|
|
70
|
-
*
|
|
71
|
-
* 🚫 'public/assets/image-1'
|
|
72
|
-
*
|
|
73
|
-
* ✅ 'public/assets/image-1.png'
|
|
74
|
-
*/
|
|
75
|
-
async fetchRemoteWriteLocal(inputUrl, outputPath, useDetectedExtension = true) {
|
|
76
|
-
try {
|
|
77
|
-
const result = await this.assetToBufferView(inputUrl);
|
|
78
|
-
const cleanData = this.cleanDataUrl(result.b64encodedData);
|
|
79
|
-
const formattedPath = useDetectedExtension ? `${outputPath}.${result.extension}` : outputPath;
|
|
80
|
-
if (/\./g.test(formattedPath) === false) {
|
|
81
|
-
throw new Error(
|
|
82
|
-
"either add false as the third argument in `fetchRemoteWriteLocal` (input, output, use-detected-file-extension) or provide an output path without a file extension"
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
this.withWs(formattedPath, Buffer.from(cleanData, "base64"));
|
|
86
|
-
} catch (err) {
|
|
87
|
-
return console.error(err);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
knownToBlockHead(inputUrl) {
|
|
91
|
-
if (inputUrl.startsWith("https://github.com")) {
|
|
92
|
-
return "GET";
|
|
93
|
-
} else if (inputUrl.startsWith("https://raw.githubusercontent.com")) {
|
|
94
|
-
return "GET";
|
|
95
|
-
} else {
|
|
96
|
-
return "HEAD";
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
*
|
|
101
|
-
* @param inputUrl remote url to fetch data from
|
|
102
|
-
* @param outputPath desired output path relative to the cwd
|
|
103
|
-
* @param useDetectedExtension optional, defaults to true
|
|
104
|
-
*
|
|
105
|
-
* if `useDetectedExtension` is false you must include the file extension in your output path →
|
|
106
|
-
*
|
|
107
|
-
* 🚫 'public/assets/image-1'
|
|
108
|
-
*
|
|
109
|
-
* ✅ 'public/assets/image-1.png'
|
|
110
|
-
*
|
|
111
|
-
* @description
|
|
112
|
-
* This method is designed for all files regardless of size, but especially for
|
|
113
|
-
* larger files that may not fit into memory (it intelligently determines the best approach on the fly)
|
|
114
|
-
* For files > 100 MB, it streams the data directly to disk instead of loading it all into memory
|
|
115
|
-
*/
|
|
116
|
-
async fetchRemoteWriteLocalLargeFiles(inputUrl, outputPathI, useDetectedExtension = true) {
|
|
117
|
-
if (!URL.canParse(inputUrl))
|
|
118
|
-
throw new Error(`invalid URL ${inputUrl} is unable to be parsed`);
|
|
119
|
-
try {
|
|
120
|
-
const meta = await this.extractRemote(inputUrl, 4096 * 48);
|
|
121
|
-
const ext = meta.format ?? "bin";
|
|
122
|
-
const size = meta.byteSize ?? 0;
|
|
123
|
-
const { unit, value } = this.autoFileSizeRaw(size);
|
|
124
|
-
console.log(
|
|
125
|
-
`fetchRemoteWriteLocalLargeFiles extracting a file of size ${value} ${unit}`
|
|
126
|
-
);
|
|
127
|
-
const formattedPath = useDetectedExtension ? `${outputPathI}.${ext}` : outputPathI;
|
|
128
|
-
this.generateDirIfDNE(this.pathHandler(formattedPath), {
|
|
129
|
-
recursive: true
|
|
130
|
-
});
|
|
131
|
-
const writeStream = fsSync.createWriteStream(
|
|
132
|
-
relative(this.cwd, formattedPath)
|
|
133
|
-
);
|
|
134
|
-
const res = await fetch(inputUrl);
|
|
135
|
-
if (!res.ok || !res.body) {
|
|
136
|
-
throw new Error(`Failed to fetch asset: ${res.statusText}`);
|
|
137
|
-
}
|
|
138
|
-
const { promise, reject, resolve } = Promise.withResolvers();
|
|
139
|
-
writeStream.on("finish", () => resolve({}));
|
|
140
|
-
writeStream.on("error", () => reject({}));
|
|
141
|
-
const reader = res.body.getReader();
|
|
142
|
-
const pump = /* @__PURE__ */ __name(async () => {
|
|
143
|
-
while (true) {
|
|
144
|
-
const { done, value: value2 } = await reader.read();
|
|
145
|
-
if (done) break;
|
|
146
|
-
writeStream.write(value2);
|
|
147
|
-
}
|
|
148
|
-
writeStream.end();
|
|
149
|
-
}, "pump");
|
|
150
|
-
await pump();
|
|
151
|
-
await promise.then(() => {
|
|
152
|
-
});
|
|
153
|
-
return;
|
|
154
|
-
} catch (err) {
|
|
155
|
-
console.error(`[fetchRemoteWriteLocalLargeFiles error]:`, err);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
export {
|
|
161
|
-
FsFetch
|
|
162
|
-
};
|
|
163
|
-
//# sourceMappingURL=chunk-4D2YBCI6.js.map
|