3.0.0 • Published 7 months ago

@varasto/fs-storage v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

@varasto/fs-storage

npm

Implementation of storage which stores data to hard disk.

Installation

$ npm install --save @varasto/fs-storage

Usage

The package provides an function called createFileSystemStorage, which returns an storage implementation that is capable of storing JSON objects into disk, where each object is identified by namespace and key, that must be valid URL slugs.

Basic usage of file system storage looks like this:

import { createFileSystemStorage } from '@varasto/fs-storage';

const storage = createFileSystemStorage({ dir: './data' });

The function takes an optional configuration object, which supports these settings:

PropertyDefault valueDescription
dir./dataDirectory where the items will be persisted into.
encodingutf-8Character encoding to use when items are stored into disk.

If dir does not exist, it will be created when an item is placed into the storage.

Custom serializers

By default, JSON.stringify is used for serializing data written to file system and JSON.parse is used for deserializing data retrieved from file system. However, you can also use your own custom serialization functions by passing them as options to the createFileSystemStorage function.

import { createFileSystemStorage } from '@varasto/fs-storage';
import { JsonObject } from 'type-fest';

const storage = createFileSystemStorage({
  serialize: (data: string): JsonObject => ({}),
  deserialize: (data: JsonObject): string => "",
});
3.0.0

7 months ago

2.0.0

7 months ago

1.2.0

3 years ago

1.1.0

3 years ago

1.2.1

3 years ago

1.0.0

3 years ago