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 | ```
|
19 | npm install fs-chunk-store
|
20 | ```
|
21 |
|
22 | ## Usage
|
23 |
|
24 | ### Back the store with a single file
|
25 |
|
26 | ``` js
|
27 | var FSChunkStore = require('fs-chunk-store')
|
28 |
|
29 | var 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
|
38 | var FSChunkStore = require('fs-chunk-store')
|
39 |
|
40 | var 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 | path: 'C:/user/' // optional: if specified the file paths will be treated as relative, not absolute
|
47 | })
|
48 | ```
|
49 | 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
|
50 |
|
51 | ### put, get, close, destroy
|
52 |
|
53 | ```js
|
54 | chunks.put(0, Buffer.from('0123456789'), function (err) {
|
55 | if (err) throw err
|
56 |
|
57 | chunks.get(0, function (err, chunk) {
|
58 | if (err) throw err
|
59 | console.log(chunk) // '0123456789' as a buffer
|
60 |
|
61 | chunks.close(function (err) {
|
62 | if (err) throw err
|
63 | console.log('/tmp/my_file file descriptor is closed')
|
64 |
|
65 | chunks.destroy(function (err) {
|
66 | if (err) throw err
|
67 | console.log('/tmp/my_file file is deleted')
|
68 | })
|
69 | })
|
70 | })
|
71 | })
|
72 | ```
|
73 |
|
74 | ## License
|
75 |
|
76 | MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).
|