@ricsam/isolate-core
v0.1.13
Published
Core utilities and class builder for isolated-vm V8 sandbox bindings
Downloads
2,035
Maintainers
Readme
@ricsam/isolate-core
Core utilities and Web Streams API for isolated-vm V8 sandbox.
Installation
npm add @ricsam/isolate-coreUsage
import { setupCore } from "@ricsam/isolate-core";
const handle = await setupCore(context);Injected Globals
ReadableStream,WritableStream,TransformStreamReadableStreamDefaultReader,WritableStreamDefaultWriterBlob,FileURL,URLSearchParamsDOMExceptionAbortController,AbortSignalTextEncoder,TextDecoder
Usage in Isolate
// Streams
const stream = new ReadableStream({
start(controller) {
controller.enqueue("chunk1");
controller.enqueue("chunk2");
controller.close();
}
});
const reader = stream.getReader();
const { value, done } = await reader.read();
// Blob
const blob = new Blob(["hello", " ", "world"], { type: "text/plain" });
const text = await blob.text(); // "hello world"
// File
const file = new File(["content"], "file.txt", { type: "text/plain" });
console.log(file.name); // "file.txt"License
MIT
