Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

fs-chunk-store

webtorrent36.5kMIT4.1.0

Filesystem (fs) chunk store that is abstract-chunk-store compliant

abstract-chunk-store, chunk, filesystem, fs, store

readme

fs-chunk-store travis npm downloads javascript style guide

Filesystem (fs) chunk store that is abstract-chunk-store compliant

abstract chunk store

Install

npm install fs-chunk-store

Usage

Back the store with a single file

var FSChunkStore = require('fs-chunk-store')

var chunks = new FSChunkStore(10, {
  path: '/tmp/my_file', // optional: path to file (default: temp file will be used)
  length: 100 // optional: file length in bytes (default: file expands based on `put`s)
})

Back the store with multiple files

var FSChunkStore = require('fs-chunk-store')

var chunks = new FSChunkStore(10, {
  files: [
    { path: 'folder/file1.txt', length: 12 },
    { path: 'folder/file2.txt', length: 8 },
    { path: 'folder/file3.txt', length: 30 }
  ],
  path: 'C:/user/' // optional: if specified the file paths will be treated as relative, not absolute
})

Specifying a path to the store will create a folder in that path, and on destroy, will delete the folder along with all it's contents

put, get, close, destroy

chunks.put(0, Buffer.from('0123456789'), function (err) {
  if (err) throw err

  chunks.get(0, function (err, chunk) {
    if (err) throw err
    console.log(chunk) // '0123456789' as a buffer

    chunks.close(function (err) {
      if (err) throw err
      console.log('/tmp/my_file file descriptor is closed')

      chunks.destroy(function (err) {
        if (err) throw err
        console.log('/tmp/my_file file is deleted')
      })
    })
  })
})

License

MIT. Copyright (c) Feross Aboukhadijeh.

changelog

4.1.0 (2023-06-15)

Features

4.0.1 (2023-01-27)

Bug Fixes

  • deps: update dependency random-access-file to v4 (#41) (33e47bd), closes #47

4.0.0 (2022-11-19)

Features

BREAKING CHANGES

  • ESM only

  • fix: don't mutate original path

  • feat: esm, modernize

3.0.1 (2022-07-03)

Bug Fixes

3.0.0 (2022-03-30)

Bug Fixes

BREAKING CHANGES

  • requires node 14+

  • remove rimraf

  • fix: no package lock

Co-authored-by: Diego Rodríguez Baquero github@diegorbaquero.com

2.0.5 (2022-03-30)

Bug Fixes

2.0.4 (2021-10-25)

Bug Fixes

  • delete residual folders by specifying relative file paths (4a5f1ed)