tachyon-drive-browser
v0.10.0
Published
Browser module for tachyon storage driver implementation
Downloads
3
Readme
tachyon-drive-browser
Browser CacheStorage and LocalStorage driver for tachyon-drive
CacheStorageDriver and LocalStorageDriver examples
export type DemoData = z.infer<typeof dataSchema>;
const stringSerializer: IPersistSerializer<DemoData, string> = {
name: 'stringSerializer',
serialize: (data: DemoData) => JSON.stringify(data),
deserialize: (buffer: string) => JSON.parse(buffer),
validator: (data: DemoData) => dataSchema.safeParse(data).success,
};
const arrayBufferSerializer: IPersistSerializer<DemoData, ArrayBuffer> = {
name: 'arrayBufferSerializer',
serialize: (data: DemoData) => new TextEncoder().encode(JSON.stringify(data)),
deserialize: (buffer: ArrayBuffer) => JSON.parse(new TextDecoder().decode(buffer)),
validator: (data: DemoData) => dataSchema.safeParse(data).success,
};
// local storage driver allows only string values.
export const localStoreDriver = new LocalStorageDriver('LocalStorageDriver', 'tachyon', stringSerializer, undefined, console);
// cache storage driver can handle string and array buffer values.
export const cacheStoreDriver = new CacheStorageDriver('CacheStorageDriver', {url: new URL('http://tachyon')}, stringSerializer, undefined, console);
export const cacheStoreDriver = new CacheStorageDriver('CacheStorageDriver', {url: new URL('http://tachyon')}, arrayBufferSerializer, undefined, console);