{"name":"random-access-storage","version":"1.4.1","description":"Easily make random-access-storage instances","main":"index.js","dependencies":{"inherits":"^2.0.3"},"devDependencies":{"standard":"^10.0.3","tape":"^4.8.0"},"scripts":{"test":"standard && tape test.js"},"repository":{"type":"git","url":"git+https://github.com/random-access-storage/random-access-storage.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"MIT","bugs":{"url":"https://github.com/random-access-storage/random-access-storage/issues"},"homepage":"https://github.com/random-access-storage/random-access-storage","gitHead":"b7864654c0fd427ba360519adbd8deb29ae52c7c","_id":"random-access-storage@1.4.1","_nodeVersion":"12.16.1","_npmVersion":"6.13.4","dist":{"integrity":"sha512-DbCc2TIzOxPaHF6KCbr8zLtiYOJQQQCBHUVNHV/SckUQobCBB2YkDtbLdxGnPwPNpJfEyMWxDAm36A2xkbxxtw==","shasum":"39a524dd428ade9161ce61a8ae677766e6117ffb","tarball":"http://registry-npm.ywwl.com/random-access-storage/download/random-access-storage-1.4.1.tgz","fileCount":7,"unpackedSize":24793,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeWR2bCRA9TVsSAnZWagAAQh4P/3wb9Q3irsUXOV+JV7WX\nSnSBrNUcjLDJHE82+/3QlGFjsBXCkWDN/DI0weRIPxMLFh1/5l21qVlOCZPf\neH1SP4AifWnctK2jmiDUpM3yGyQ4Ig2omWFSG9qPAVaNKRaBJVuT4/cMB+aT\nLC98NtuDndiiDMct7bHTZ4o7uvvyYWO/GMto7Bbe4nV3KIsFjle+lcYDwQ9W\nfVIijXQ4m7sA+C0RUyVSgb87W5VD+5gt5eFMSCljGdkSqV7NqHpvb6Tnz/Vc\nosvNQiJFl1/UgwlbUvouIMt06qNfTgLVomjeNltQ6TtOvjy34CkLZ85IAkqT\nS0tNR6cPCx2VYXRRo76edTwMQhkGu5Yp22mTjtxergvof9OIk5s8B0w9IvzZ\nUp3WtflGXOPXM/zUHm9wW1ZNLhy53aNF5Mud+CtXp1/8Dia7W+CCneYHkSZD\nPGne3kX01ZFEGtvyT7b56+X+Zf/KzKyfR7NxA2NaLvDPfOiR0oJMtmjHYOcU\nhDUzkJCqgc/X6D4gWeA2QHNvrTFQUIwBpGRgNKTA/aIbCXUG5VnRFCaYw+vW\ncTMGlFGfLovlOAfpd5KSfYQjdmRV7UrnMEvaTlHXjzfU+OSmCIhn4Nf9P4BW\nspHMkqV6f2HiOhD2ck1kcCr9Wn9yNMy67sk0cQ77A5YMNrSc/I/YmmNSQ7pk\nR4v3\r\n=mTxZ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD7LE12BAhO/vYCLeVeAIG+tUQl74RUENbld4d4d+mpdwIgWpFJ9D3uAnCHrcpaHOXO235hhi4WotmK/kScV8CuyR4="}],"size":5963,"noattachment":false,"key":"/random-access-storage/-/random-access-storage-1.4.1.tgz"},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/random-access-storage_1.4.1_1582898586969_0.9565696268067292"},"_hasShrinkwrap":false,"readme":"# random-access-storage\n\nEasily make random-access-storage instances\n\n```\nnpm install random-access-storage\n```\n\nA random-access-storage instance is a common interface for a storage abstraction, that provides the following core api.\n\n* `read(offset, size)` - Read a buffer at a custom offset.\n* `write(offset, data)` - Write a buffer to a custom offset.\n* `del(offset, size)` - Delete data at a custom offset.\n\nThis module exposes a base class that implements most of the plumbing and flow you'd usually want to implement when making one.\n\n## Usage\n\n``` js\nconst RandomAccessStorage = require('random-access-storage')\nconst fs = require('fs')\n\nconst file = fileReader('index.js')\n\nfile.read(0, 10, (err, buf) => console.log('0-10: ' + buf.toString()))\nfile.read(40, 15, (err, buf) => console.log('40-55: ' + buf.toString()))\nfile.close()\n\nfunction fileReader (name) {\n  let fd = 0\n  return new RandomAccessStorage({\n    open: function (req) {\n      // called once automatically before the first read call\n      fs.open(name, 'r', function (err, res) {\n        if (err) return req.callback(err)\n        fd = res\n        req.callback(null)\n      })\n    },\n    read: function (req) {\n      const buf = Buffer.allocUnsafe(req.size)\n      fs.read(fd, buf, 0, buf.length, req.offset, function (err, read) {\n        if (err) return req.callback(err)\n        if (read < buf.length) return req.callback(new Error('Could not read'))\n        req.callback(null, buf)\n      })\n    },\n    close: function (req) {\n      if (!fd) return req.callback(null)\n      fs.close(fd, err => req.callback(err))\n    }\n  })\n}\n```\n\n## API\n\n#### `const storage = new RandomAccessStorage([options])`\n\nMake a new instance. Options include:\n\n``` js\n{\n  createAlways: false, // always create storage on first open\n  open: fn, // sets ._open\n  read: fn, // sets ._read\n  write: fn, // sets ._write\n  del: fn, // sets ._del\n  truncate: fn, // sets ._truncate\n  stat: fn, // sets ._stat\n  suspend: fn, // sets ._suspend\n  close: fn, // sets ._close\n  unlink: fn // sets ._unlink\n}\n```\n\n#### `storage.readable`\n\nTrue if the storage implements `._read`.\n\n#### `storage.writable`\n\nTrue if the storage implements `._write`.\n\n#### `storage.deletable`\n\nTrue if the storage implements `._del`.\n\n#### `storage.truncatable`\n\nTrue if the storage implements `._truncate`.\n\n#### `storage.statable`\n\nTrue if the storage implements `._stat`.\n\n#### `storage.opened`\n\nTrue if the storage has been fully opened.\n\n#### `storage.closed`\n\nTrue if the storage has been fully closed.\n\n#### `storage.unlinked`\n\nTrue if the storage has been fully unlinked.\n\n#### `storage.writing`\n\nTrue if the storage is currently being written to.\n\n#### `storage.on('open')`\n\nEmitted when the storage is fully open.\n\n#### `storage.on('close')`\n\nEmitted when the storage is fully closed.\n\n#### `storage.on('unlink')`\n\nEmitted when the storage is fully unlinked.\n\n#### `storage.on('suspend')`\n\nEmitted when the storage is fully suspended\n\n#### `storage.on('unsuspend')`\n\nEmitted when the storage comes out of suspension.\n\n#### `storage.open(cb)`\n\nExplicitly open the storage. If you do not call this yourself,\nit will automatically called before any read/write/del/stat operation.\n\nIt is safe to call this more than once.\n\nTriggers *one* call to `_open` if you implement that.\n\n#### `storage._open(req)`\n\nImplement storage open.\n\n* `req.create` is `true` if the storage should be created.\n\nCall `req.callback` when it is fully opened.\n\n#### `storage.read(offset, size, callback)`\n\nRead the specified bytes from the storage at the specified byte offset.\nCalls the callback with a `(err, buffer)`.\n\n#### `storage._read(req)`\n\nImplement storage read.\n\n* `req.offset` contains the byte offset you should read at.\n* `req.size` contains the amount of bytes you should read.\n\nCall `req.callback(err, buffer)` when the read is completed.\n\nNote that this is guaranteed to run after the storage has been opened and not after it has been closed.\n\n#### `storage.write(offset, buffer, [callback])`\n\nWrite the specified buffer to the specified byte offset. Optionally pass a callback that is called with `(err)` when the write has completed.\n\n#### `storage._write(req)`\n\nImplement storage write.\n\n* `req.offset` contains the byte offset you should write at.\n* `req.data` contains the buffer you should write.\n\nCall `req.callback(err)` when the write is completed.\n\nNote that this is guaranteed to run after the storage has been opened and not after it has been closed.\n\n#### `storage.del(offset, size, [callback])`\n\nDelete the specified amount of bytes at the specified offset. Optionally pass a callback that is called with `(err)` when the delete has completed.\n\n#### `storage._del(req)`\n\nImplement storage delete.\n\n* `req.offset` contains the byte offset to delete at.\n* `req.size` contains the amount of bytes to delete.\n\nCall `req.callback(err)` when the delete has completed.\n\nNote that this is guaranteed to run after the storage has been opened and not after it has been closed.\n\n#### `storage.truncate(offset, [callback])`\n\nTruncate the storage at the specified offset. Optionally pass a callback that is called with `(err)` when the truncate has completed.\n\n#### `storage._truncate(req)`\n\nImplement storage truncate. Defaults to `storage._del(req)`.\n\n* `req.offset` contains the byte offset to truncate at.\n\nCall `req.callback(err)` when the truncate has completed.\n\nNote that this is guaranteed to run after the storage has been opened and not after it has been closed.\n\n#### `storage.stat(callback)`\n\nStat the storage. Should return an object with useful information about the underlying storage, including:\n\n```\n{\n  size: number // how many bytes of data is stored?\n}\n```\n\n#### `storage._stat(req)`\n\nImplement storage stat.\n\nCall `req.callback(err, statObject)` when the stat has completed.\n\nNote that this is guaranteed to run after the storage has been opened and not after it has been closed.\n\n#### `storage.suspend([callback])`\n\nSuspend (temporarily close) the storage instance.\n\n#### `storage._suspend(req)`\n\nImplement storage suspend. Defaults to calling `_close`.\n\nOptionally implement this to add a way for your storage instance to temporarily free resources.\n\nCall `req.callback(err)` when the storage has been fully suspended.\n\n#### `storage.close([callback])`\n\nClose the storage instance.\n\n#### `storage._close(req)`\n\nImplement storage close.\n\nCall `req.callback(err)` when the storage is fully closed.\n\nNote this is guaranteed to run after all pending read/write/stat/del operations has finished and no methods will run after.\n\n#### `storage.unlink([callback])`\n\nUnlink the storage instance, removing all underlying data.\n\n#### `storage._unlink(req)`\n\nImplement storage unlink.\n\nCall `req.callback(err)` when the storage has been fully unlinked.\n\nNote this is guaranteed to run after `.close()` has been called and no methods will be run after.\n\n## License\n\nMIT\n","publish_time":1582898587075,"_cnpm_publish_time":1582898587075,"dist-tags":{"latest":"3.0.2"}}