fs-blob-storage
![npm](https://img.shields.io/npm/v/fs-blob-storage.svg)
Blob storage on filesystem with promises API.
Requirements
This module requires ES6 with Node >= 6.
Installation
npm install fs-blob-storage
Typescript:
npm install -D fs-blob-storage @types/node
Usage
const FsBlobStorage = require('fs-blob-storage')
Typescript:
import FsBlobStorage from 'fs-blob-storage'
constructor
const storage = new FsBlobStorage(options)
Options:
exclusive
if is true then can't create new object if already exists with
the same key (optional, default: false)path
is a directory path of the storage
Example:
const storage = new FsBlobStorage({
path: '/var/spool/mail',
exclusive: true
})
createWriteStream
const writable = await storage.createWriteStream(key, options)
Options:
ext
is a default extension added to file name for the object (optional,
default: "")part
is a extension added to file name which can be later commited
(optional, default: ".part")encoding
is a encoding for created file (optional, default: "utf8")
Creates a writable stream for a new object in the storage. Object is stored with
the file name based on key
and ext
and part
. Throws an error if has
occurred and if the file already exists for exclusive mode.
createReadStream
const readable = await storage.createWriteStream(key, options)
Options:
ext
is a default extension added to file name for the object (optional,
default: "")encoding
is a encoding for created file (optional, default: "utf8")
Creates a readable stream for an existing object in the storage. Throws an error
if has occurred or the object doesn't exist or its size is zero.
commit
await storage.commit(key, options)
Options:
ext
is a default extension added to file name for the object (optional,
default: "")part
is a extension added to file name which can be later commited
(optional, default: ".part")
Commits the object in the storage. It means that file name for the object is
renamed and the additional extension for partial objects is removed. Throws an
error if has occurred or the object doesn't exist.
remove
await storage.remove(key, options)
Options:
ext
is a default extension added to file name for the object (optional,
default: "")
Removes the object from the storage. Throws an error if has occurred or the
object doesn't exist.
License
Copyright (c) 2018 Piotr Roszatycki piotr.roszatycki@gmail.com
MIT