@remix-run/file-storage 0.8.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/LICENSE +21 -0
- package/README.md +83 -0
- package/dist/file-storage.cjs +19 -0
- package/dist/file-storage.cjs.map +7 -0
- package/dist/file-storage.d.ts +2 -0
- package/dist/file-storage.d.ts.map +1 -0
- package/dist/file-storage.js +1 -0
- package/dist/file-storage.js.map +7 -0
- package/dist/lib/file-storage.d.ts +158 -0
- package/dist/lib/file-storage.d.ts.map +1 -0
- package/dist/lib/local-file-storage.d.ts +26 -0
- package/dist/lib/local-file-storage.d.ts.map +1 -0
- package/dist/lib/memory-file-storage.d.ts +17 -0
- package/dist/lib/memory-file-storage.d.ts.map +1 -0
- package/dist/local.cjs +904 -0
- package/dist/local.cjs.map +7 -0
- package/dist/local.d.ts +2 -0
- package/dist/local.d.ts.map +1 -0
- package/dist/local.js +867 -0
- package/dist/local.js.map +7 -0
- package/dist/memory.cjs +86 -0
- package/dist/memory.cjs.map +7 -0
- package/dist/memory.d.ts +2 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +63 -0
- package/dist/memory.js.map +7 -0
- package/package.json +71 -0
- package/src/file-storage.ts +7 -0
- package/src/lib/file-storage.ts +164 -0
- package/src/lib/local-file-storage.ts +183 -0
- package/src/lib/memory-file-storage.ts +78 -0
- package/src/local.ts +1 -0
- package/src/memory.ts +1 -0
package/dist/local.cjs
ADDED
|
@@ -0,0 +1,904 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/local.ts
|
|
31
|
+
var local_exports = {};
|
|
32
|
+
__export(local_exports, {
|
|
33
|
+
LocalFileStorage: () => LocalFileStorage
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(local_exports);
|
|
36
|
+
|
|
37
|
+
// src/lib/local-file-storage.ts
|
|
38
|
+
var fs2 = __toESM(require("node:fs"), 1);
|
|
39
|
+
var fsp = __toESM(require("node:fs/promises"), 1);
|
|
40
|
+
var path2 = __toESM(require("node:path"), 1);
|
|
41
|
+
|
|
42
|
+
// ../lazy-file/src/fs.ts
|
|
43
|
+
var fs = __toESM(require("node:fs"), 1);
|
|
44
|
+
var path = __toESM(require("node:path"), 1);
|
|
45
|
+
|
|
46
|
+
// ../../node_modules/.pnpm/mrmime@2.0.0/node_modules/mrmime/index.mjs
|
|
47
|
+
var mimes = {
|
|
48
|
+
"3g2": "video/3gpp2",
|
|
49
|
+
"3gp": "video/3gpp",
|
|
50
|
+
"3gpp": "video/3gpp",
|
|
51
|
+
"3mf": "model/3mf",
|
|
52
|
+
"aac": "audio/aac",
|
|
53
|
+
"ac": "application/pkix-attr-cert",
|
|
54
|
+
"adp": "audio/adpcm",
|
|
55
|
+
"adts": "audio/aac",
|
|
56
|
+
"ai": "application/postscript",
|
|
57
|
+
"aml": "application/automationml-aml+xml",
|
|
58
|
+
"amlx": "application/automationml-amlx+zip",
|
|
59
|
+
"amr": "audio/amr",
|
|
60
|
+
"apng": "image/apng",
|
|
61
|
+
"appcache": "text/cache-manifest",
|
|
62
|
+
"appinstaller": "application/appinstaller",
|
|
63
|
+
"appx": "application/appx",
|
|
64
|
+
"appxbundle": "application/appxbundle",
|
|
65
|
+
"asc": "application/pgp-keys",
|
|
66
|
+
"atom": "application/atom+xml",
|
|
67
|
+
"atomcat": "application/atomcat+xml",
|
|
68
|
+
"atomdeleted": "application/atomdeleted+xml",
|
|
69
|
+
"atomsvc": "application/atomsvc+xml",
|
|
70
|
+
"au": "audio/basic",
|
|
71
|
+
"avci": "image/avci",
|
|
72
|
+
"avcs": "image/avcs",
|
|
73
|
+
"avif": "image/avif",
|
|
74
|
+
"aw": "application/applixware",
|
|
75
|
+
"bdoc": "application/bdoc",
|
|
76
|
+
"bin": "application/octet-stream",
|
|
77
|
+
"bmp": "image/bmp",
|
|
78
|
+
"bpk": "application/octet-stream",
|
|
79
|
+
"btf": "image/prs.btif",
|
|
80
|
+
"btif": "image/prs.btif",
|
|
81
|
+
"buffer": "application/octet-stream",
|
|
82
|
+
"ccxml": "application/ccxml+xml",
|
|
83
|
+
"cdfx": "application/cdfx+xml",
|
|
84
|
+
"cdmia": "application/cdmi-capability",
|
|
85
|
+
"cdmic": "application/cdmi-container",
|
|
86
|
+
"cdmid": "application/cdmi-domain",
|
|
87
|
+
"cdmio": "application/cdmi-object",
|
|
88
|
+
"cdmiq": "application/cdmi-queue",
|
|
89
|
+
"cer": "application/pkix-cert",
|
|
90
|
+
"cgm": "image/cgm",
|
|
91
|
+
"cjs": "application/node",
|
|
92
|
+
"class": "application/java-vm",
|
|
93
|
+
"coffee": "text/coffeescript",
|
|
94
|
+
"conf": "text/plain",
|
|
95
|
+
"cpl": "application/cpl+xml",
|
|
96
|
+
"cpt": "application/mac-compactpro",
|
|
97
|
+
"crl": "application/pkix-crl",
|
|
98
|
+
"css": "text/css",
|
|
99
|
+
"csv": "text/csv",
|
|
100
|
+
"cu": "application/cu-seeme",
|
|
101
|
+
"cwl": "application/cwl",
|
|
102
|
+
"cww": "application/prs.cww",
|
|
103
|
+
"davmount": "application/davmount+xml",
|
|
104
|
+
"dbk": "application/docbook+xml",
|
|
105
|
+
"deb": "application/octet-stream",
|
|
106
|
+
"def": "text/plain",
|
|
107
|
+
"deploy": "application/octet-stream",
|
|
108
|
+
"dib": "image/bmp",
|
|
109
|
+
"disposition-notification": "message/disposition-notification",
|
|
110
|
+
"dist": "application/octet-stream",
|
|
111
|
+
"distz": "application/octet-stream",
|
|
112
|
+
"dll": "application/octet-stream",
|
|
113
|
+
"dmg": "application/octet-stream",
|
|
114
|
+
"dms": "application/octet-stream",
|
|
115
|
+
"doc": "application/msword",
|
|
116
|
+
"dot": "application/msword",
|
|
117
|
+
"dpx": "image/dpx",
|
|
118
|
+
"drle": "image/dicom-rle",
|
|
119
|
+
"dsc": "text/prs.lines.tag",
|
|
120
|
+
"dssc": "application/dssc+der",
|
|
121
|
+
"dtd": "application/xml-dtd",
|
|
122
|
+
"dump": "application/octet-stream",
|
|
123
|
+
"dwd": "application/atsc-dwd+xml",
|
|
124
|
+
"ear": "application/java-archive",
|
|
125
|
+
"ecma": "application/ecmascript",
|
|
126
|
+
"elc": "application/octet-stream",
|
|
127
|
+
"emf": "image/emf",
|
|
128
|
+
"eml": "message/rfc822",
|
|
129
|
+
"emma": "application/emma+xml",
|
|
130
|
+
"emotionml": "application/emotionml+xml",
|
|
131
|
+
"eps": "application/postscript",
|
|
132
|
+
"epub": "application/epub+zip",
|
|
133
|
+
"exe": "application/octet-stream",
|
|
134
|
+
"exi": "application/exi",
|
|
135
|
+
"exp": "application/express",
|
|
136
|
+
"exr": "image/aces",
|
|
137
|
+
"ez": "application/andrew-inset",
|
|
138
|
+
"fdf": "application/fdf",
|
|
139
|
+
"fdt": "application/fdt+xml",
|
|
140
|
+
"fits": "image/fits",
|
|
141
|
+
"g3": "image/g3fax",
|
|
142
|
+
"gbr": "application/rpki-ghostbusters",
|
|
143
|
+
"geojson": "application/geo+json",
|
|
144
|
+
"gif": "image/gif",
|
|
145
|
+
"glb": "model/gltf-binary",
|
|
146
|
+
"gltf": "model/gltf+json",
|
|
147
|
+
"gml": "application/gml+xml",
|
|
148
|
+
"gpx": "application/gpx+xml",
|
|
149
|
+
"gram": "application/srgs",
|
|
150
|
+
"grxml": "application/srgs+xml",
|
|
151
|
+
"gxf": "application/gxf",
|
|
152
|
+
"gz": "application/gzip",
|
|
153
|
+
"h261": "video/h261",
|
|
154
|
+
"h263": "video/h263",
|
|
155
|
+
"h264": "video/h264",
|
|
156
|
+
"heic": "image/heic",
|
|
157
|
+
"heics": "image/heic-sequence",
|
|
158
|
+
"heif": "image/heif",
|
|
159
|
+
"heifs": "image/heif-sequence",
|
|
160
|
+
"hej2": "image/hej2k",
|
|
161
|
+
"held": "application/atsc-held+xml",
|
|
162
|
+
"hjson": "application/hjson",
|
|
163
|
+
"hlp": "application/winhlp",
|
|
164
|
+
"hqx": "application/mac-binhex40",
|
|
165
|
+
"hsj2": "image/hsj2",
|
|
166
|
+
"htm": "text/html",
|
|
167
|
+
"html": "text/html",
|
|
168
|
+
"ics": "text/calendar",
|
|
169
|
+
"ief": "image/ief",
|
|
170
|
+
"ifb": "text/calendar",
|
|
171
|
+
"iges": "model/iges",
|
|
172
|
+
"igs": "model/iges",
|
|
173
|
+
"img": "application/octet-stream",
|
|
174
|
+
"in": "text/plain",
|
|
175
|
+
"ini": "text/plain",
|
|
176
|
+
"ink": "application/inkml+xml",
|
|
177
|
+
"inkml": "application/inkml+xml",
|
|
178
|
+
"ipfix": "application/ipfix",
|
|
179
|
+
"iso": "application/octet-stream",
|
|
180
|
+
"its": "application/its+xml",
|
|
181
|
+
"jade": "text/jade",
|
|
182
|
+
"jar": "application/java-archive",
|
|
183
|
+
"jhc": "image/jphc",
|
|
184
|
+
"jls": "image/jls",
|
|
185
|
+
"jp2": "image/jp2",
|
|
186
|
+
"jpe": "image/jpeg",
|
|
187
|
+
"jpeg": "image/jpeg",
|
|
188
|
+
"jpf": "image/jpx",
|
|
189
|
+
"jpg": "image/jpeg",
|
|
190
|
+
"jpg2": "image/jp2",
|
|
191
|
+
"jpgm": "image/jpm",
|
|
192
|
+
"jpgv": "video/jpeg",
|
|
193
|
+
"jph": "image/jph",
|
|
194
|
+
"jpm": "image/jpm",
|
|
195
|
+
"jpx": "image/jpx",
|
|
196
|
+
"js": "text/javascript",
|
|
197
|
+
"json": "application/json",
|
|
198
|
+
"json5": "application/json5",
|
|
199
|
+
"jsonld": "application/ld+json",
|
|
200
|
+
"jsonml": "application/jsonml+json",
|
|
201
|
+
"jsx": "text/jsx",
|
|
202
|
+
"jt": "model/jt",
|
|
203
|
+
"jxr": "image/jxr",
|
|
204
|
+
"jxra": "image/jxra",
|
|
205
|
+
"jxrs": "image/jxrs",
|
|
206
|
+
"jxs": "image/jxs",
|
|
207
|
+
"jxsc": "image/jxsc",
|
|
208
|
+
"jxsi": "image/jxsi",
|
|
209
|
+
"jxss": "image/jxss",
|
|
210
|
+
"kar": "audio/midi",
|
|
211
|
+
"ktx": "image/ktx",
|
|
212
|
+
"ktx2": "image/ktx2",
|
|
213
|
+
"less": "text/less",
|
|
214
|
+
"lgr": "application/lgr+xml",
|
|
215
|
+
"list": "text/plain",
|
|
216
|
+
"litcoffee": "text/coffeescript",
|
|
217
|
+
"log": "text/plain",
|
|
218
|
+
"lostxml": "application/lost+xml",
|
|
219
|
+
"lrf": "application/octet-stream",
|
|
220
|
+
"m1v": "video/mpeg",
|
|
221
|
+
"m21": "application/mp21",
|
|
222
|
+
"m2a": "audio/mpeg",
|
|
223
|
+
"m2v": "video/mpeg",
|
|
224
|
+
"m3a": "audio/mpeg",
|
|
225
|
+
"m4a": "audio/mp4",
|
|
226
|
+
"m4p": "application/mp4",
|
|
227
|
+
"m4s": "video/iso.segment",
|
|
228
|
+
"ma": "application/mathematica",
|
|
229
|
+
"mads": "application/mads+xml",
|
|
230
|
+
"maei": "application/mmt-aei+xml",
|
|
231
|
+
"man": "text/troff",
|
|
232
|
+
"manifest": "text/cache-manifest",
|
|
233
|
+
"map": "application/json",
|
|
234
|
+
"mar": "application/octet-stream",
|
|
235
|
+
"markdown": "text/markdown",
|
|
236
|
+
"mathml": "application/mathml+xml",
|
|
237
|
+
"mb": "application/mathematica",
|
|
238
|
+
"mbox": "application/mbox",
|
|
239
|
+
"md": "text/markdown",
|
|
240
|
+
"mdx": "text/mdx",
|
|
241
|
+
"me": "text/troff",
|
|
242
|
+
"mesh": "model/mesh",
|
|
243
|
+
"meta4": "application/metalink4+xml",
|
|
244
|
+
"metalink": "application/metalink+xml",
|
|
245
|
+
"mets": "application/mets+xml",
|
|
246
|
+
"mft": "application/rpki-manifest",
|
|
247
|
+
"mid": "audio/midi",
|
|
248
|
+
"midi": "audio/midi",
|
|
249
|
+
"mime": "message/rfc822",
|
|
250
|
+
"mj2": "video/mj2",
|
|
251
|
+
"mjp2": "video/mj2",
|
|
252
|
+
"mjs": "text/javascript",
|
|
253
|
+
"mml": "text/mathml",
|
|
254
|
+
"mods": "application/mods+xml",
|
|
255
|
+
"mov": "video/quicktime",
|
|
256
|
+
"mp2": "audio/mpeg",
|
|
257
|
+
"mp21": "application/mp21",
|
|
258
|
+
"mp2a": "audio/mpeg",
|
|
259
|
+
"mp3": "audio/mpeg",
|
|
260
|
+
"mp4": "video/mp4",
|
|
261
|
+
"mp4a": "audio/mp4",
|
|
262
|
+
"mp4s": "application/mp4",
|
|
263
|
+
"mp4v": "video/mp4",
|
|
264
|
+
"mpd": "application/dash+xml",
|
|
265
|
+
"mpe": "video/mpeg",
|
|
266
|
+
"mpeg": "video/mpeg",
|
|
267
|
+
"mpf": "application/media-policy-dataset+xml",
|
|
268
|
+
"mpg": "video/mpeg",
|
|
269
|
+
"mpg4": "video/mp4",
|
|
270
|
+
"mpga": "audio/mpeg",
|
|
271
|
+
"mpp": "application/dash-patch+xml",
|
|
272
|
+
"mrc": "application/marc",
|
|
273
|
+
"mrcx": "application/marcxml+xml",
|
|
274
|
+
"ms": "text/troff",
|
|
275
|
+
"mscml": "application/mediaservercontrol+xml",
|
|
276
|
+
"msh": "model/mesh",
|
|
277
|
+
"msi": "application/octet-stream",
|
|
278
|
+
"msix": "application/msix",
|
|
279
|
+
"msixbundle": "application/msixbundle",
|
|
280
|
+
"msm": "application/octet-stream",
|
|
281
|
+
"msp": "application/octet-stream",
|
|
282
|
+
"mtl": "model/mtl",
|
|
283
|
+
"musd": "application/mmt-usd+xml",
|
|
284
|
+
"mxf": "application/mxf",
|
|
285
|
+
"mxmf": "audio/mobile-xmf",
|
|
286
|
+
"mxml": "application/xv+xml",
|
|
287
|
+
"n3": "text/n3",
|
|
288
|
+
"nb": "application/mathematica",
|
|
289
|
+
"nq": "application/n-quads",
|
|
290
|
+
"nt": "application/n-triples",
|
|
291
|
+
"obj": "model/obj",
|
|
292
|
+
"oda": "application/oda",
|
|
293
|
+
"oga": "audio/ogg",
|
|
294
|
+
"ogg": "audio/ogg",
|
|
295
|
+
"ogv": "video/ogg",
|
|
296
|
+
"ogx": "application/ogg",
|
|
297
|
+
"omdoc": "application/omdoc+xml",
|
|
298
|
+
"onepkg": "application/onenote",
|
|
299
|
+
"onetmp": "application/onenote",
|
|
300
|
+
"onetoc": "application/onenote",
|
|
301
|
+
"onetoc2": "application/onenote",
|
|
302
|
+
"opf": "application/oebps-package+xml",
|
|
303
|
+
"opus": "audio/ogg",
|
|
304
|
+
"otf": "font/otf",
|
|
305
|
+
"owl": "application/rdf+xml",
|
|
306
|
+
"oxps": "application/oxps",
|
|
307
|
+
"p10": "application/pkcs10",
|
|
308
|
+
"p7c": "application/pkcs7-mime",
|
|
309
|
+
"p7m": "application/pkcs7-mime",
|
|
310
|
+
"p7s": "application/pkcs7-signature",
|
|
311
|
+
"p8": "application/pkcs8",
|
|
312
|
+
"pdf": "application/pdf",
|
|
313
|
+
"pfr": "application/font-tdpfr",
|
|
314
|
+
"pgp": "application/pgp-encrypted",
|
|
315
|
+
"pkg": "application/octet-stream",
|
|
316
|
+
"pki": "application/pkixcmp",
|
|
317
|
+
"pkipath": "application/pkix-pkipath",
|
|
318
|
+
"pls": "application/pls+xml",
|
|
319
|
+
"png": "image/png",
|
|
320
|
+
"prc": "model/prc",
|
|
321
|
+
"prf": "application/pics-rules",
|
|
322
|
+
"provx": "application/provenance+xml",
|
|
323
|
+
"ps": "application/postscript",
|
|
324
|
+
"pskcxml": "application/pskc+xml",
|
|
325
|
+
"pti": "image/prs.pti",
|
|
326
|
+
"qt": "video/quicktime",
|
|
327
|
+
"raml": "application/raml+yaml",
|
|
328
|
+
"rapd": "application/route-apd+xml",
|
|
329
|
+
"rdf": "application/rdf+xml",
|
|
330
|
+
"relo": "application/p2p-overlay+xml",
|
|
331
|
+
"rif": "application/reginfo+xml",
|
|
332
|
+
"rl": "application/resource-lists+xml",
|
|
333
|
+
"rld": "application/resource-lists-diff+xml",
|
|
334
|
+
"rmi": "audio/midi",
|
|
335
|
+
"rnc": "application/relax-ng-compact-syntax",
|
|
336
|
+
"rng": "application/xml",
|
|
337
|
+
"roa": "application/rpki-roa",
|
|
338
|
+
"roff": "text/troff",
|
|
339
|
+
"rq": "application/sparql-query",
|
|
340
|
+
"rs": "application/rls-services+xml",
|
|
341
|
+
"rsat": "application/atsc-rsat+xml",
|
|
342
|
+
"rsd": "application/rsd+xml",
|
|
343
|
+
"rsheet": "application/urc-ressheet+xml",
|
|
344
|
+
"rss": "application/rss+xml",
|
|
345
|
+
"rtf": "text/rtf",
|
|
346
|
+
"rtx": "text/richtext",
|
|
347
|
+
"rusd": "application/route-usd+xml",
|
|
348
|
+
"s3m": "audio/s3m",
|
|
349
|
+
"sbml": "application/sbml+xml",
|
|
350
|
+
"scq": "application/scvp-cv-request",
|
|
351
|
+
"scs": "application/scvp-cv-response",
|
|
352
|
+
"sdp": "application/sdp",
|
|
353
|
+
"senmlx": "application/senml+xml",
|
|
354
|
+
"sensmlx": "application/sensml+xml",
|
|
355
|
+
"ser": "application/java-serialized-object",
|
|
356
|
+
"setpay": "application/set-payment-initiation",
|
|
357
|
+
"setreg": "application/set-registration-initiation",
|
|
358
|
+
"sgi": "image/sgi",
|
|
359
|
+
"sgm": "text/sgml",
|
|
360
|
+
"sgml": "text/sgml",
|
|
361
|
+
"shex": "text/shex",
|
|
362
|
+
"shf": "application/shf+xml",
|
|
363
|
+
"shtml": "text/html",
|
|
364
|
+
"sieve": "application/sieve",
|
|
365
|
+
"sig": "application/pgp-signature",
|
|
366
|
+
"sil": "audio/silk",
|
|
367
|
+
"silo": "model/mesh",
|
|
368
|
+
"siv": "application/sieve",
|
|
369
|
+
"slim": "text/slim",
|
|
370
|
+
"slm": "text/slim",
|
|
371
|
+
"sls": "application/route-s-tsid+xml",
|
|
372
|
+
"smi": "application/smil+xml",
|
|
373
|
+
"smil": "application/smil+xml",
|
|
374
|
+
"snd": "audio/basic",
|
|
375
|
+
"so": "application/octet-stream",
|
|
376
|
+
"spdx": "text/spdx",
|
|
377
|
+
"spp": "application/scvp-vp-response",
|
|
378
|
+
"spq": "application/scvp-vp-request",
|
|
379
|
+
"spx": "audio/ogg",
|
|
380
|
+
"sql": "application/sql",
|
|
381
|
+
"sru": "application/sru+xml",
|
|
382
|
+
"srx": "application/sparql-results+xml",
|
|
383
|
+
"ssdl": "application/ssdl+xml",
|
|
384
|
+
"ssml": "application/ssml+xml",
|
|
385
|
+
"stk": "application/hyperstudio",
|
|
386
|
+
"stl": "model/stl",
|
|
387
|
+
"stpx": "model/step+xml",
|
|
388
|
+
"stpxz": "model/step-xml+zip",
|
|
389
|
+
"stpz": "model/step+zip",
|
|
390
|
+
"styl": "text/stylus",
|
|
391
|
+
"stylus": "text/stylus",
|
|
392
|
+
"svg": "image/svg+xml",
|
|
393
|
+
"svgz": "image/svg+xml",
|
|
394
|
+
"swidtag": "application/swid+xml",
|
|
395
|
+
"t": "text/troff",
|
|
396
|
+
"t38": "image/t38",
|
|
397
|
+
"td": "application/urc-targetdesc+xml",
|
|
398
|
+
"tei": "application/tei+xml",
|
|
399
|
+
"teicorpus": "application/tei+xml",
|
|
400
|
+
"text": "text/plain",
|
|
401
|
+
"tfi": "application/thraud+xml",
|
|
402
|
+
"tfx": "image/tiff-fx",
|
|
403
|
+
"tif": "image/tiff",
|
|
404
|
+
"tiff": "image/tiff",
|
|
405
|
+
"toml": "application/toml",
|
|
406
|
+
"tr": "text/troff",
|
|
407
|
+
"trig": "application/trig",
|
|
408
|
+
"ts": "video/mp2t",
|
|
409
|
+
"tsd": "application/timestamped-data",
|
|
410
|
+
"tsv": "text/tab-separated-values",
|
|
411
|
+
"ttc": "font/collection",
|
|
412
|
+
"ttf": "font/ttf",
|
|
413
|
+
"ttl": "text/turtle",
|
|
414
|
+
"ttml": "application/ttml+xml",
|
|
415
|
+
"txt": "text/plain",
|
|
416
|
+
"u3d": "model/u3d",
|
|
417
|
+
"u8dsn": "message/global-delivery-status",
|
|
418
|
+
"u8hdr": "message/global-headers",
|
|
419
|
+
"u8mdn": "message/global-disposition-notification",
|
|
420
|
+
"u8msg": "message/global",
|
|
421
|
+
"ubj": "application/ubjson",
|
|
422
|
+
"uri": "text/uri-list",
|
|
423
|
+
"uris": "text/uri-list",
|
|
424
|
+
"urls": "text/uri-list",
|
|
425
|
+
"vcard": "text/vcard",
|
|
426
|
+
"vrml": "model/vrml",
|
|
427
|
+
"vtt": "text/vtt",
|
|
428
|
+
"vxml": "application/voicexml+xml",
|
|
429
|
+
"war": "application/java-archive",
|
|
430
|
+
"wasm": "application/wasm",
|
|
431
|
+
"wav": "audio/wav",
|
|
432
|
+
"weba": "audio/webm",
|
|
433
|
+
"webm": "video/webm",
|
|
434
|
+
"webmanifest": "application/manifest+json",
|
|
435
|
+
"webp": "image/webp",
|
|
436
|
+
"wgsl": "text/wgsl",
|
|
437
|
+
"wgt": "application/widget",
|
|
438
|
+
"wif": "application/watcherinfo+xml",
|
|
439
|
+
"wmf": "image/wmf",
|
|
440
|
+
"woff": "font/woff",
|
|
441
|
+
"woff2": "font/woff2",
|
|
442
|
+
"wrl": "model/vrml",
|
|
443
|
+
"wsdl": "application/wsdl+xml",
|
|
444
|
+
"wspolicy": "application/wspolicy+xml",
|
|
445
|
+
"x3d": "model/x3d+xml",
|
|
446
|
+
"x3db": "model/x3d+fastinfoset",
|
|
447
|
+
"x3dbz": "model/x3d+binary",
|
|
448
|
+
"x3dv": "model/x3d-vrml",
|
|
449
|
+
"x3dvz": "model/x3d+vrml",
|
|
450
|
+
"x3dz": "model/x3d+xml",
|
|
451
|
+
"xaml": "application/xaml+xml",
|
|
452
|
+
"xav": "application/xcap-att+xml",
|
|
453
|
+
"xca": "application/xcap-caps+xml",
|
|
454
|
+
"xcs": "application/calendar+xml",
|
|
455
|
+
"xdf": "application/xcap-diff+xml",
|
|
456
|
+
"xdssc": "application/dssc+xml",
|
|
457
|
+
"xel": "application/xcap-el+xml",
|
|
458
|
+
"xenc": "application/xenc+xml",
|
|
459
|
+
"xer": "application/patch-ops-error+xml",
|
|
460
|
+
"xfdf": "application/xfdf",
|
|
461
|
+
"xht": "application/xhtml+xml",
|
|
462
|
+
"xhtml": "application/xhtml+xml",
|
|
463
|
+
"xhvml": "application/xv+xml",
|
|
464
|
+
"xlf": "application/xliff+xml",
|
|
465
|
+
"xm": "audio/xm",
|
|
466
|
+
"xml": "text/xml",
|
|
467
|
+
"xns": "application/xcap-ns+xml",
|
|
468
|
+
"xop": "application/xop+xml",
|
|
469
|
+
"xpl": "application/xproc+xml",
|
|
470
|
+
"xsd": "application/xml",
|
|
471
|
+
"xsf": "application/prs.xsf+xml",
|
|
472
|
+
"xsl": "application/xml",
|
|
473
|
+
"xslt": "application/xml",
|
|
474
|
+
"xspf": "application/xspf+xml",
|
|
475
|
+
"xvm": "application/xv+xml",
|
|
476
|
+
"xvml": "application/xv+xml",
|
|
477
|
+
"yaml": "text/yaml",
|
|
478
|
+
"yang": "application/yang",
|
|
479
|
+
"yin": "application/yin+xml",
|
|
480
|
+
"yml": "text/yaml",
|
|
481
|
+
"zip": "application/zip"
|
|
482
|
+
};
|
|
483
|
+
function lookup(extn) {
|
|
484
|
+
let tmp = ("" + extn).trim().toLowerCase();
|
|
485
|
+
let idx = tmp.lastIndexOf(".");
|
|
486
|
+
return mimes[!~idx ? tmp : tmp.substring(++idx)];
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// ../lazy-file/src/lib/byte-range.ts
|
|
490
|
+
function getByteLength(range, size) {
|
|
491
|
+
let [start, end] = getIndexes(range, size);
|
|
492
|
+
return end - start;
|
|
493
|
+
}
|
|
494
|
+
function getIndexes(range, size) {
|
|
495
|
+
let start = Math.min(Math.max(0, range.start < 0 ? size + range.start : range.start), size);
|
|
496
|
+
let end = Math.min(Math.max(start, range.end < 0 ? size + range.end : range.end), size);
|
|
497
|
+
return [start, end];
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// ../lazy-file/src/lib/lazy-file.ts
|
|
501
|
+
var LazyBlob = class extends Blob {
|
|
502
|
+
#content;
|
|
503
|
+
constructor(parts, options) {
|
|
504
|
+
super([], options);
|
|
505
|
+
this.#content = new BlobContent(parts, options);
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Returns the blob's contents as an [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer).
|
|
509
|
+
*
|
|
510
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/arrayBuffer)
|
|
511
|
+
*/
|
|
512
|
+
async arrayBuffer() {
|
|
513
|
+
return this.#content.arrayBuffer();
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Returns the blob's contents as a byte array.
|
|
517
|
+
*
|
|
518
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/bytes)
|
|
519
|
+
*/
|
|
520
|
+
async bytes() {
|
|
521
|
+
return this.#content.bytes();
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* The size of the blob in bytes.
|
|
525
|
+
*
|
|
526
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/size)
|
|
527
|
+
*/
|
|
528
|
+
get size() {
|
|
529
|
+
return this.#content.size;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Returns a new [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) that contains the data in the specified range.
|
|
533
|
+
*
|
|
534
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice)
|
|
535
|
+
*/
|
|
536
|
+
slice(start, end, contentType) {
|
|
537
|
+
return this.#content.slice(start, end, contentType);
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Returns a stream that can be used to read the blob's contents.
|
|
541
|
+
*
|
|
542
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/stream)
|
|
543
|
+
*/
|
|
544
|
+
stream() {
|
|
545
|
+
return this.#content.stream();
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Returns the blob's contents as a string.
|
|
549
|
+
*
|
|
550
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/text)
|
|
551
|
+
*/
|
|
552
|
+
async text() {
|
|
553
|
+
return this.#content.text();
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
var LazyFile = class extends File {
|
|
557
|
+
#content;
|
|
558
|
+
constructor(parts, name, options) {
|
|
559
|
+
super([], name, options);
|
|
560
|
+
this.#content = new BlobContent(parts, options);
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Returns the file's content as an [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer).
|
|
564
|
+
*
|
|
565
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/arrayBuffer)
|
|
566
|
+
*/
|
|
567
|
+
async arrayBuffer() {
|
|
568
|
+
return this.#content.arrayBuffer();
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Returns the file's contents as a byte array.
|
|
572
|
+
*
|
|
573
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/bytes)
|
|
574
|
+
*/
|
|
575
|
+
async bytes() {
|
|
576
|
+
return this.#content.bytes();
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* The size of the file in bytes.
|
|
580
|
+
*
|
|
581
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/size)
|
|
582
|
+
*/
|
|
583
|
+
get size() {
|
|
584
|
+
return this.#content.size;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Returns a new [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) that contains the data in the specified range.
|
|
588
|
+
*
|
|
589
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice)
|
|
590
|
+
*/
|
|
591
|
+
slice(start, end, contentType) {
|
|
592
|
+
return this.#content.slice(start, end, contentType);
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Returns a stream that can be used to read the file's contents.
|
|
596
|
+
*
|
|
597
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/stream)
|
|
598
|
+
*/
|
|
599
|
+
stream() {
|
|
600
|
+
return this.#content.stream();
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Returns the file's contents as a string.
|
|
604
|
+
*
|
|
605
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/text)
|
|
606
|
+
*/
|
|
607
|
+
async text() {
|
|
608
|
+
return this.#content.text();
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
var BlobContent = class {
|
|
612
|
+
source;
|
|
613
|
+
totalSize;
|
|
614
|
+
range;
|
|
615
|
+
type;
|
|
616
|
+
constructor(parts, options) {
|
|
617
|
+
if (Array.isArray(parts)) {
|
|
618
|
+
this.source = [];
|
|
619
|
+
this.totalSize = 0;
|
|
620
|
+
for (let part of parts) {
|
|
621
|
+
if (part instanceof Blob) {
|
|
622
|
+
this.source.push(part);
|
|
623
|
+
this.totalSize += part.size;
|
|
624
|
+
} else {
|
|
625
|
+
let array;
|
|
626
|
+
if (typeof part === "string") {
|
|
627
|
+
array = new TextEncoder().encode(part);
|
|
628
|
+
} else if (ArrayBuffer.isView(part)) {
|
|
629
|
+
array = new Uint8Array(part.buffer, part.byteOffset, part.byteLength);
|
|
630
|
+
} else {
|
|
631
|
+
array = new Uint8Array(part);
|
|
632
|
+
}
|
|
633
|
+
this.source.push(array);
|
|
634
|
+
this.totalSize += array.byteLength;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
} else {
|
|
638
|
+
this.source = parts;
|
|
639
|
+
this.totalSize = parts.byteLength;
|
|
640
|
+
}
|
|
641
|
+
this.range = options?.range;
|
|
642
|
+
this.type = options?.type ?? "";
|
|
643
|
+
}
|
|
644
|
+
async arrayBuffer() {
|
|
645
|
+
return (await this.bytes()).buffer;
|
|
646
|
+
}
|
|
647
|
+
async bytes() {
|
|
648
|
+
let result = new Uint8Array(this.size);
|
|
649
|
+
let offset = 0;
|
|
650
|
+
for await (let chunk of this.stream()) {
|
|
651
|
+
result.set(chunk, offset);
|
|
652
|
+
offset += chunk.length;
|
|
653
|
+
}
|
|
654
|
+
return result;
|
|
655
|
+
}
|
|
656
|
+
get size() {
|
|
657
|
+
return this.range != null ? getByteLength(this.range, this.totalSize) : this.totalSize;
|
|
658
|
+
}
|
|
659
|
+
slice(start = 0, end, contentType = "") {
|
|
660
|
+
let range = this.range != null ? (
|
|
661
|
+
// file.slice().slice() is additive
|
|
662
|
+
{ start: this.range.start + start, end: this.range.end + (end ?? 0) }
|
|
663
|
+
) : { start, end: end ?? this.size };
|
|
664
|
+
return new LazyBlob(this.source, { range, type: contentType });
|
|
665
|
+
}
|
|
666
|
+
stream() {
|
|
667
|
+
if (this.range != null) {
|
|
668
|
+
let [start, end] = getIndexes(this.range, this.totalSize);
|
|
669
|
+
return Array.isArray(this.source) ? streamContentArray(this.source, start, end) : this.source.stream(start, end);
|
|
670
|
+
}
|
|
671
|
+
return Array.isArray(this.source) ? streamContentArray(this.source) : this.source.stream();
|
|
672
|
+
}
|
|
673
|
+
async text() {
|
|
674
|
+
return new TextDecoder("utf-8").decode(await this.bytes());
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
function streamContentArray(content, start = 0, end = Infinity) {
|
|
678
|
+
let index = 0;
|
|
679
|
+
let bytesRead = 0;
|
|
680
|
+
return new ReadableStream({
|
|
681
|
+
async pull(controller) {
|
|
682
|
+
if (index >= content.length) {
|
|
683
|
+
controller.close();
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
let hasPushed = false;
|
|
687
|
+
function pushChunk(chunk) {
|
|
688
|
+
let chunkLength = chunk.byteLength;
|
|
689
|
+
if (!(bytesRead + chunkLength < start || bytesRead >= end)) {
|
|
690
|
+
let startIndex = Math.max(start - bytesRead, 0);
|
|
691
|
+
let endIndex = Math.min(end - bytesRead, chunkLength);
|
|
692
|
+
controller.enqueue(chunk.subarray(startIndex, endIndex));
|
|
693
|
+
hasPushed = true;
|
|
694
|
+
}
|
|
695
|
+
bytesRead += chunkLength;
|
|
696
|
+
}
|
|
697
|
+
async function pushPart(part) {
|
|
698
|
+
if (part instanceof Blob) {
|
|
699
|
+
if (bytesRead + part.size <= start) {
|
|
700
|
+
bytesRead += part.size;
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
for await (let chunk of part.stream()) {
|
|
704
|
+
pushChunk(chunk);
|
|
705
|
+
if (bytesRead >= end) {
|
|
706
|
+
break;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
} else {
|
|
710
|
+
pushChunk(part);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
while (!hasPushed && index < content.length) {
|
|
714
|
+
await pushPart(content[index++]);
|
|
715
|
+
if (bytesRead >= end) {
|
|
716
|
+
controller.close();
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// ../lazy-file/src/fs.ts
|
|
725
|
+
function openFile(filename, options) {
|
|
726
|
+
let stats = fs.statSync(filename);
|
|
727
|
+
if (!stats.isFile()) {
|
|
728
|
+
throw new Error(`Path "${filename}" is not a file`);
|
|
729
|
+
}
|
|
730
|
+
let content = {
|
|
731
|
+
byteLength: stats.size,
|
|
732
|
+
stream(start, end) {
|
|
733
|
+
return streamFile(filename, start, end);
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
return new LazyFile(content, options?.name ?? path.basename(filename), {
|
|
737
|
+
type: options?.type ?? lookup(filename),
|
|
738
|
+
lastModified: options?.lastModified ?? stats.mtimeMs
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
function streamFile(filename, start = 0, end = Infinity) {
|
|
742
|
+
let read = fs.createReadStream(filename, { start, end: end - 1 }).iterator();
|
|
743
|
+
return new ReadableStream({
|
|
744
|
+
async pull(controller) {
|
|
745
|
+
let { done, value } = await read.next();
|
|
746
|
+
if (done) {
|
|
747
|
+
controller.close();
|
|
748
|
+
} else {
|
|
749
|
+
controller.enqueue(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
function writeFile(to, file) {
|
|
755
|
+
return new Promise(async (resolve2, reject) => {
|
|
756
|
+
let writeStream = typeof to === "string" ? fs.createWriteStream(to) : fs.createWriteStream("ignored", { fd: to });
|
|
757
|
+
try {
|
|
758
|
+
for await (let chunk of file.stream()) {
|
|
759
|
+
writeStream.write(chunk);
|
|
760
|
+
}
|
|
761
|
+
writeStream.end(() => {
|
|
762
|
+
resolve2();
|
|
763
|
+
});
|
|
764
|
+
} catch (error) {
|
|
765
|
+
writeStream.end(() => {
|
|
766
|
+
reject(error);
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
// src/lib/local-file-storage.ts
|
|
773
|
+
var LocalFileStorage = class {
|
|
774
|
+
#dirname;
|
|
775
|
+
/**
|
|
776
|
+
* @param directory The directory where files are stored
|
|
777
|
+
*/
|
|
778
|
+
constructor(directory) {
|
|
779
|
+
this.#dirname = path2.resolve(directory);
|
|
780
|
+
try {
|
|
781
|
+
let stats = fs2.statSync(this.#dirname);
|
|
782
|
+
if (!stats.isDirectory()) {
|
|
783
|
+
throw new Error(`Path "${this.#dirname}" is not a directory`);
|
|
784
|
+
}
|
|
785
|
+
} catch (error) {
|
|
786
|
+
if (!isNoEntityError(error)) {
|
|
787
|
+
throw error;
|
|
788
|
+
}
|
|
789
|
+
fs2.mkdirSync(this.#dirname, { recursive: true });
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
async get(key) {
|
|
793
|
+
let { filePath, metaPath } = await this.#getPaths(key);
|
|
794
|
+
try {
|
|
795
|
+
let meta = await readMetadata(metaPath);
|
|
796
|
+
return openFile(filePath, {
|
|
797
|
+
lastModified: meta.lastModified,
|
|
798
|
+
name: meta.name,
|
|
799
|
+
type: meta.type
|
|
800
|
+
});
|
|
801
|
+
} catch (error) {
|
|
802
|
+
if (!isNoEntityError(error)) {
|
|
803
|
+
throw error;
|
|
804
|
+
}
|
|
805
|
+
return null;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
async has(key) {
|
|
809
|
+
let { metaPath } = await this.#getPaths(key);
|
|
810
|
+
try {
|
|
811
|
+
await fsp.access(metaPath);
|
|
812
|
+
return true;
|
|
813
|
+
} catch {
|
|
814
|
+
return false;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
async list(options) {
|
|
818
|
+
let { cursor, includeMetadata = false, limit = 32, prefix } = options ?? {};
|
|
819
|
+
let files = [];
|
|
820
|
+
let foundCursor = cursor === void 0;
|
|
821
|
+
let nextCursor;
|
|
822
|
+
let lastHash;
|
|
823
|
+
outerLoop: for await (let subdir of await fsp.opendir(this.#dirname)) {
|
|
824
|
+
if (!subdir.isDirectory()) continue;
|
|
825
|
+
for await (let file of await fsp.opendir(path2.join(this.#dirname, subdir.name))) {
|
|
826
|
+
if (!file.isFile() || !file.name.endsWith(".meta.json")) continue;
|
|
827
|
+
let hash = file.name.slice(0, -10);
|
|
828
|
+
if (foundCursor) {
|
|
829
|
+
let meta = await readMetadata(path2.join(this.#dirname, subdir.name, file.name));
|
|
830
|
+
if (prefix != null && !meta.key.startsWith(prefix)) {
|
|
831
|
+
continue;
|
|
832
|
+
}
|
|
833
|
+
if (files.length >= limit) {
|
|
834
|
+
nextCursor = lastHash;
|
|
835
|
+
break outerLoop;
|
|
836
|
+
}
|
|
837
|
+
if (includeMetadata) {
|
|
838
|
+
let size = (await fsp.stat(path2.join(this.#dirname, subdir.name, `${hash}.dat`))).size;
|
|
839
|
+
files.push({ ...meta, size });
|
|
840
|
+
} else {
|
|
841
|
+
files.push({ key: meta.key });
|
|
842
|
+
}
|
|
843
|
+
} else if (hash === cursor) {
|
|
844
|
+
foundCursor = true;
|
|
845
|
+
}
|
|
846
|
+
lastHash = hash;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
return {
|
|
850
|
+
cursor: nextCursor,
|
|
851
|
+
files
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
async put(key, file) {
|
|
855
|
+
await this.set(key, file);
|
|
856
|
+
return await this.get(key);
|
|
857
|
+
}
|
|
858
|
+
async remove(key) {
|
|
859
|
+
let { filePath, metaPath } = await this.#getPaths(key);
|
|
860
|
+
try {
|
|
861
|
+
await Promise.all([fsp.unlink(filePath), fsp.unlink(metaPath)]);
|
|
862
|
+
} catch (error) {
|
|
863
|
+
if (!isNoEntityError(error)) {
|
|
864
|
+
throw error;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
async set(key, file) {
|
|
869
|
+
let { directory, filePath, metaPath } = await this.#getPaths(key);
|
|
870
|
+
await fsp.mkdir(directory, { recursive: true });
|
|
871
|
+
await writeFile(filePath, file);
|
|
872
|
+
let meta = {
|
|
873
|
+
key,
|
|
874
|
+
lastModified: file.lastModified,
|
|
875
|
+
name: file.name,
|
|
876
|
+
type: file.type
|
|
877
|
+
};
|
|
878
|
+
await fsp.writeFile(metaPath, JSON.stringify(meta));
|
|
879
|
+
}
|
|
880
|
+
async #getPaths(key) {
|
|
881
|
+
let hash = await computeHash(key);
|
|
882
|
+
let directory = path2.join(this.#dirname, hash.slice(0, 2));
|
|
883
|
+
return {
|
|
884
|
+
directory,
|
|
885
|
+
filePath: path2.join(directory, `${hash}.dat`),
|
|
886
|
+
metaPath: path2.join(directory, `${hash}.meta.json`)
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
async function readMetadata(metaPath) {
|
|
891
|
+
return JSON.parse(await fsp.readFile(metaPath, "utf-8"));
|
|
892
|
+
}
|
|
893
|
+
async function computeHash(key, algorithm = "SHA-256") {
|
|
894
|
+
let digest = await crypto.subtle.digest(algorithm, new TextEncoder().encode(key));
|
|
895
|
+
return Array.from(new Uint8Array(digest)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
896
|
+
}
|
|
897
|
+
function isNoEntityError(obj) {
|
|
898
|
+
return obj instanceof Error && "code" in obj && obj.code === "ENOENT";
|
|
899
|
+
}
|
|
900
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
901
|
+
0 && (module.exports = {
|
|
902
|
+
LocalFileStorage
|
|
903
|
+
});
|
|
904
|
+
//# sourceMappingURL=local.cjs.map
|