UNPKG

2.19 kBMarkdownView Raw
1# fs-chunk-store [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]
2
3[travis-image]: https://img.shields.io/travis/feross/fs-chunk-store/master.svg
4[travis-url]: https://travis-ci.org/feross/fs-chunk-store
5[npm-image]: https://img.shields.io/npm/v/fs-chunk-store.svg
6[npm-url]: https://npmjs.org/package/fs-chunk-store
7[downloads-image]: https://img.shields.io/npm/dm/fs-chunk-store.svg
8[downloads-url]: https://npmjs.org/package/fs-chunk-store
9[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
10[standard-url]: https://standardjs.com
11
12#### Filesystem (fs) chunk store that is [abstract-chunk-store](https://github.com/mafintosh/abstract-chunk-store) compliant
13
14[![abstract chunk store](https://cdn.rawgit.com/mafintosh/abstract-chunk-store/master/badge.svg)](https://github.com/mafintosh/abstract-chunk-store)
15
16## Install
17
18```
19npm install fs-chunk-store
20```
21
22## Usage
23
24### Back the store with a single file
25
26``` js
27var FSChunkStore = require('fs-chunk-store')
28
29var chunks = new FSChunkStore(10, {
30 path: '/tmp/my_file', // optional: path to file (default: temp file will be used)
31 length: 100 // optional: file length in bytes (default: file expands based on `put`s)
32})
33```
34
35### Back the store with multiple files
36
37``` js
38var FSChunkStore = require('fs-chunk-store')
39
40var chunks = new FSChunkStore(10, {
41 files: [
42 { path: 'folder/file1.txt', length: 12 },
43 { path: 'folder/file2.txt', length: 8 },
44 { path: 'folder/file3.txt', length: 30 }
45 ]
46})
47```
48
49### put, get, close, destroy
50
51```js
52chunks.put(0, Buffer.from('0123456789'), function (err) {
53 if (err) throw err
54
55 chunks.get(0, function (err, chunk) {
56 if (err) throw err
57 console.log(chunk) // '0123456789' as a buffer
58
59 chunks.close(function (err) {
60 if (err) throw err
61 console.log('/tmp/my_file file descriptor is closed')
62
63 chunks.destroy(function (err) {
64 if (err) throw err
65 console.log('/tmp/my_file file is deleted')
66 })
67 })
68 })
69})
70```
71
72## License
73
74MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).