|
1 | 1 | # random-access-idb-mutable-file
|
| 2 | + |
2 | 3 | [![travis][travis.icon]][travis.url]
|
3 | 4 | [![package][version.icon] ![downloads][downloads.icon]][package.url]
|
4 | 5 | [![styled with prettier][prettier.icon]][prettier.url]
|
5 | 6 |
|
| 7 | +[random-access][random-access-storage] storage layer over [IDBMutableFile][], which is **non-standard** IndexedDB extension in Gecko to provide virtual file system API with-in the IndexedDB. |
6 | 8 |
|
7 |
| - |
8 |
| -random-access-storage provider via non-standard IDBMutableFile API |
| 9 | +This library will only work in Firefox (unless other browsers implement [IDBMutableFile][] API) and it's mostly targeted at [WebExtensions][]. It mostly amis to be a drop-in replacement for [random-access-file][]. It is also an alternative to [random-access-idb][] that is able to avoid loading all of the file content for random read / writes at the expanse of limited runtime suport. |
9 | 10 |
|
10 | 11 | ## Usage
|
11 | 12 |
|
12 |
| -### Import |
13 |
| - |
14 |
| -Rest of the the document & provided code examples assumes that library is installed (with yarn or npm) and imported as follows: |
15 |
| - |
16 | 13 | ```js
|
17 |
| -import * as random-access-idb-mutable-file from "random-access-idb-mutable-file" |
| 14 | +import RandomAccess from "random-access-idb-mutable-file" |
| 15 | + |
| 16 | +const main = async (filename, options) => { |
| 17 | + const randomAccessFile = await RandomAccess.mount() |
| 18 | + |
| 19 | + const file = randomAccessFile(filename, options) |
| 20 | + file.write(10, Buffer.from("hello"), error => { |
| 21 | + // write a buffer to offset 10 |
| 22 | + file.read(10, 5, (error, buffer) => { |
| 23 | + console.log(buffer) // read 5 bytes from offset 10 |
| 24 | + file.close(() => { |
| 25 | + console.log("file is closed") |
| 26 | + }) |
| 27 | + }) |
| 28 | + }) |
| 29 | +} |
18 | 30 | ```
|
19 | 31 |
|
20 |
| - |
21 |
| - |
22 | 32 | ## Install
|
23 | 33 |
|
24 | 34 | npm install random-access-idb-mutable-file
|
25 | 35 |
|
26 | 36 | [travis.icon]: https://travis-ci.org/Gozala/random-access-idb-mutable-file.svg?branch=master
|
27 | 37 | [travis.url]: https://travis-ci.org/Gozala/random-access-idb-mutable-file
|
28 |
| - |
29 | 38 | [version.icon]: https://img.shields.io/npm/v/random-access-idb-mutable-file.svg
|
30 | 39 | [package.url]: https://npmjs.org/package/random-access-idb-mutable-file
|
31 |
| - |
32 | 40 | [downloads.icon]: https://img.shields.io/npm/dm/random-access-idb-mutable-file.svg
|
33 | 41 | [downloads.url]: https://npmjs.org/package/random-access-idb-mutable-file
|
34 |
| - |
35 |
| -[prettier.icon]:https://img.shields.io/badge/styled_with-prettier-ff69b4.svg |
36 |
| -[prettier.url]:https://github.com/prettier/prettier |
| 42 | +[prettier.icon]: https://img.shields.io/badge/styled_with-prettier-ff69b4.svg |
| 43 | +[prettier.url]: https://github.com/prettier/prettier |
| 44 | +[random-access-storage]: https://github.com/random-access-storage/random-access-storage |
| 45 | +[random-access-file]: https://github.com/random-access-storage/random-access-file |
| 46 | +[idbmutablefile]: https://developer.mozilla.org/en-US/docs/Web/API/IDBMutableFile |
| 47 | +[webextensions]: https://developer.mozilla.org/en-US/Add-ons/WebExtensions |
| 48 | +[random-access-idb]: https://github.com/random-access-storage/random-access-idb |
0 commit comments