UNPKG

1.33 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const typeson_js_1 = __importDefault(require("./typeson.js"));
7const { TypesonPromise, toStringTag } = typeson_js_1.default;
8const file = {
9 file: {
10 test(x) { return toStringTag(x) === 'File'; },
11 replace(f) {
12 return this.replaceAsync(f);
13 },
14 revive({ name, type, buffer, lastModified }) {
15 return new File([buffer], name, { type, lastModified });
16 },
17 replaceAsync(f) {
18 return new TypesonPromise((resolve, reject) => {
19 const reader = new FileReader();
20 reader.addEventListener('load', () => {
21 resolve({
22 type: f.type,
23 buffer: reader.result,
24 name: f.name,
25 lastModified: f.lastModified
26 });
27 });
28 reader.addEventListener('error', () => {
29 reject(reader.error);
30 });
31 reader.readAsArrayBuffer(f);
32 });
33 }
34 }
35};
36exports.default = file;
37//# sourceMappingURL=file.js.map
\No newline at end of file