3.1.0 • Published 4 years ago

fs-blob-storage v3.1.0

Weekly downloads
7
License
MIT
Repository
github
Last release
4 years ago

fs-blob-storage

Build Status Coverage Status npm

Blob storage on filesystem, with streams and promises API.

Features:

  • Simple API
  • Read and write file streams
  • Partial files
  • Safe, atomic operations
  • Works with any POSIX or NTFS filesystem
  • NFS friendly locking

Requirements

This module requires Node >= 10.

Installation

npm install fs-blob-storage

Additionally for Typescript:

npm install -D @types/node

Usage

const {FsBlobStorage, DEFAULT_EXT, DEFAULT_PART} = require("fs-blob-storage")

Typescript:

import FsBlobStorage from "fs-blob-storage"
// or
import {FsBlobStorage, DEFAULT_EXT, DEFAULT_PART} from "fs-blob-storage"

DEFAULT_EXT

The default ext option is ''

DEFAULT_PART

The default part option is '.part'

constructor

const storage = new FsBlobStorage(options)

Options:

  • ext is a default ext argument for methods (optional, default: DEFAULT_EXT)
  • part is a default part argument for methods (optional, default: DEFAULT_PART)
  • exclusive if is true then can't create new object if already exists with the same key (optional, default: false)
  • fs is a File System module (optional, default: require('fs'))
  • path is a directory path of the storage (optional, default: '.')

Example:

const storage = new FsBlobStorage({
  part: ".lock",
  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: this.ext)
  • part is a extension added to file name which can be later commited (optional, default: this.part)
  • encoding is a encoding for created file (optional, default: null)

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: this.ext)
  • part is a extension added to file name which can be later commited (optional, default: this.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: this.ext)

Removes the object from the storage. Throws an error if has occurred or the object doesn't exist.

Bugs

This storage doesn't work correctly on NTFS filesystem mounted in Linux in VirtualBox. In this case no partial files should be used.

License

Copyright (c) 2018-2020 Piotr Roszatycki piotr.roszatycki@gmail.com

MIT

3.1.0

4 years ago

3.0.0

4 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago