@ezdevlol/memfs
Version:
In-memory file-system with Node's fs API.
24 lines (23 loc) • 950 B
JavaScript
import { CborEncoder } from '@jsonjoy.com/json-pack/lib/cbor/CborEncoder';
import { CborDecoder } from '@jsonjoy.com/json-pack/lib/cbor/CborDecoder';
import { fromSnapshotSync, toSnapshotSync } from './sync';
import { fromSnapshot, toSnapshot } from './async';
import { writer } from './shared';
const encoder = new CborEncoder(writer);
const decoder = new CborDecoder();
export const toBinarySnapshotSync = (options) => {
const snapshot = toSnapshotSync(options);
return encoder.encode(snapshot);
};
export const fromBinarySnapshotSync = (uint8, options) => {
const snapshot = decoder.decode(uint8);
fromSnapshotSync(snapshot, options);
};
export const toBinarySnapshot = async (options) => {
const snapshot = await toSnapshot(options);
return encoder.encode(snapshot);
};
export const fromBinarySnapshot = async (uint8, options) => {
const snapshot = decoder.decode(uint8);
await fromSnapshot(snapshot, options);
};