one
Version:
One is a React framework for web, iOS, and Android apps.
89 lines (88 loc) • 2.18 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var streams_exports = {};
__export(streams_exports, {
FileSystemReadableStreamSource: () => FileSystemReadableStreamSource,
FileSystemWritableSink: () => FileSystemWritableSink
});
module.exports = __toCommonJS(streams_exports);
var FileSystemReadableStreamSource = class {
handle;
size = 1024;
type = "bytes";
constructor(handle) {
this.handle = handle;
}
cancel() {
this.handle.close();
}
async pull(controller) {
const view = controller.byobRequest?.view;
let bytes;
try {
bytes = await this.handle.readBytes(view ? view.byteLength : this.size);
} catch (error) {
try {
this.handle.close();
} catch {}
throw error;
}
if (!view) {
if (bytes.length === 0) {
this.handle.close();
controller.close();
return;
}
controller.enqueue(bytes);
return;
}
if (bytes.length === 0) {
this.handle.close();
controller.close();
controller.byobRequest?.respond(0);
return;
}
new Uint8Array(view.buffer, view.byteOffset, view.byteLength).set(bytes);
controller.byobRequest?.respond(bytes.length);
}
};
var FileSystemWritableSink = class {
handle;
constructor(handle) {
this.handle = handle;
}
abort() {
this.close();
}
close() {
this.handle.close();
}
async write(chunk) {
try {
await this.handle.writeBytes(chunk);
} catch (error) {
try {
this.handle.close();
} catch {}
throw error;
}
}
};