{"_id":"random-access-storage","_rev":"1393220","name":"random-access-storage","description":"Easily make random-access-storage instances","dist-tags":{"latest":"1.4.2"},"maintainers":[{"name":"mafintosh","email":""}],"time":{"modified":"2021-11-04T09:11:01.000Z","created":"2018-02-04T17:28:13.857Z","1.4.2":"2021-11-04T09:06:22.108Z","1.4.1":"2020-02-28T14:03:07.075Z","1.4.0":"2019-06-12T11:47:38.460Z","1.3.0":"2018-06-21T07:21:09.177Z","1.2.0":"2018-05-02T09:33:47.321Z","1.1.1":"2018-02-05T14:18:31.415Z","1.1.0":"2018-02-05T08:22:26.056Z","1.0.0":"2018-02-04T21:02:35.731Z","0.0.0":"2018-02-04T17:28:13.857Z"},"users":{},"author":{"name":"Mathias Buus","url":"@mafintosh"},"repository":{"type":"git","url":"git+https://github.com/random-access-storage/random-access-storage.git"},"versions":{"1.4.2":{"name":"random-access-storage","version":"1.4.2","description":"Easily make random-access-storage instances","main":"index.js","dependencies":{"inherits":"^2.0.3","queue-tick":"^1.0.0"},"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":"618a8f53b3293c8180f02a4576febf4c982d0321","_id":"random-access-storage@1.4.2","_nodeVersion":"16.8.0","_npmVersion":"6.14.15","dist":{"shasum":"dd5c800fb5974c6c9811ebb41cdf896730aa3994","size":6094,"noattachment":false,"key":"/random-access-storage/-/random-access-storage-1.4.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/random-access-storage/download/random-access-storage-1.4.2.tgz"},"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"directories":{},"maintainers":[{"name":"mafintosh","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/random-access-storage_1.4.2_1636016781955_0.31854069667844853"},"_hasShrinkwrap":false,"publish_time":1636016782108,"_cnpm_publish_time":1636016782108},"1.4.1":{"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":{"shasum":"39a524dd428ade9161ce61a8ae677766e6117ffb","size":5963,"noattachment":false,"key":"/random-access-storage/-/random-access-storage-1.4.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/random-access-storage/download/random-access-storage-1.4.1.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"_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,"publish_time":1582898587075,"_cnpm_publish_time":1582898587075},"1.4.0":{"name":"random-access-storage","version":"1.4.0","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":"55650e6e6f6b06e0a45382fbc11086c15ef67879","_id":"random-access-storage@1.4.0","_npmVersion":"6.4.1","_nodeVersion":"10.15.1","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"dist":{"shasum":"cbe5b5ccfb38680aac7b78a050d9f0a5ef36841f","size":5774,"noattachment":false,"key":"/random-access-storage/-/random-access-storage-1.4.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/random-access-storage/download/random-access-storage-1.4.0.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/random-access-storage_1.4.0_1560340058284_0.35045027794822414"},"_hasShrinkwrap":false,"publish_time":1560340058460,"_cnpm_publish_time":1560340058460},"1.3.0":{"name":"random-access-storage","version":"1.3.0","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":"20adf785a9742e380231c27ba516f311cef9a2cb","_id":"random-access-storage@1.3.0","_npmVersion":"6.1.0","_nodeVersion":"10.3.0","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"dist":{"shasum":"d27e4d897b79dc4358afc2bbe553044e5c8cfe35","size":5700,"noattachment":false,"key":"/random-access-storage/-/random-access-storage-1.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/random-access-storage/download/random-access-storage-1.3.0.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/random-access-storage_1.3.0_1529565669114_0.6711676475516484"},"_hasShrinkwrap":false,"publish_time":1529565669177,"_cnpm_publish_time":1529565669177},"1.2.0":{"name":"random-access-storage","version":"1.2.0","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":"cd10440e1cbc7e1b9e0102335905cf5a1e4d7467","_id":"random-access-storage@1.2.0","_npmVersion":"5.6.0","_nodeVersion":"9.11.1","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"dist":{"shasum":"5c93f662207daad8f4e3c916afa562af0a1ce776","size":5594,"noattachment":false,"key":"/random-access-storage/-/random-access-storage-1.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/random-access-storage/download/random-access-storage-1.2.0.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/random-access-storage_1.2.0_1525253627236_0.7403347703654399"},"_hasShrinkwrap":false,"publish_time":1525253627321,"_cnpm_publish_time":1525253627321},"1.1.1":{"name":"random-access-storage","version":"1.1.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":"73daef183036830735b7d8ec5f73d01e9e552074","_id":"random-access-storage@1.1.1","_npmVersion":"5.6.0","_nodeVersion":"9.5.0","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"dist":{"shasum":"e3364013887367d54e2ad0a134c7bf68eb9229e5","size":5478,"noattachment":false,"key":"/random-access-storage/-/random-access-storage-1.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/random-access-storage/download/random-access-storage-1.1.1.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/random-access-storage-1.1.1.tgz_1517840310493_0.19981975085102022"},"directories":{},"publish_time":1517840311415,"_hasShrinkwrap":false,"_cnpm_publish_time":1517840311415},"1.1.0":{"name":"random-access-storage","version":"1.1.0","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":"1655b5950e035c3a0d0501b84a5a1de8f9e8b9ba","_id":"random-access-storage@1.1.0","_npmVersion":"5.6.0","_nodeVersion":"9.5.0","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"dist":{"shasum":"c8551c46a3d07adaccb9ccc4fd1a1f6e3a818abd","size":5448,"noattachment":false,"key":"/random-access-storage/-/random-access-storage-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/random-access-storage/download/random-access-storage-1.1.0.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/random-access-storage-1.1.0.tgz_1517818945081_0.48862304794602096"},"directories":{},"publish_time":1517818946056,"_cnpm_publish_time":1517818946056,"_hasShrinkwrap":false},"1.0.0":{"name":"random-access-storage","version":"1.0.0","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":"6ffae087a15e5a225db7357d0472d7e12b21842c","_id":"random-access-storage@1.0.0","_npmVersion":"5.6.0","_nodeVersion":"9.5.0","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"dist":{"shasum":"ff76c70dbc9f552514273db05d718a7f01608541","size":5007,"noattachment":false,"key":"/random-access-storage/-/random-access-storage-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/random-access-storage/download/random-access-storage-1.0.0.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/random-access-storage-1.0.0.tgz_1517778154793_0.7478278297930956"},"directories":{},"publish_time":1517778155731,"_hasShrinkwrap":false,"_cnpm_publish_time":1517778155731},"0.0.0":{"name":"random-access-storage","version":"0.0.0","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":"35efd846be2cc1499230b92728ace5cfad20e677","_id":"random-access-storage@0.0.0","_npmVersion":"5.6.0","_nodeVersion":"9.5.0","_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"dist":{"shasum":"df1f6227d130254ca7bbaf182312fbffdbd22eeb","size":4096,"noattachment":false,"key":"/random-access-storage/-/random-access-storage-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/random-access-storage/download/random-access-storage-0.0.0.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/random-access-storage-0.0.0.tgz_1517765292899_0.3913068105466664"},"directories":{},"publish_time":1517765293857,"_hasShrinkwrap":false,"_cnpm_publish_time":1517765293857}},"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\nvar randomAccess = require('random-access-storage')\nvar fs = require('fs')\n\nvar 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  var fd = 0\n  return randomAccess({\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      var 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#### `var storage = randomAccessStorage([options])`\n\nMake a new instance. Options include:\n\n``` js\n{\n  open: fn, // sets ._open\n  openReadonly: fn, // sets ._openReadonly\n  read: fn, // sets ._read\n  write: fn, // sets ._write\n  del: fn, // sets ._del\n  stat: fn, // sets ._stat\n  close: fn, // sets ._close\n  destroy: fn // sets ._destroy\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.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.destroyed`\n\nTrue is the destorage has been fully destroyed.\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('destroy')`\n\nEmitted when the storage is fully destroyed.\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\nIf you implement `_openReadonly` and the operation that triggers the open\nis not a write/del then `_openReadonly` will be called instead.\n\nIf a write is later performed a `_open` call will be triggered as well,\nexpecting you to open the storage in read/write mode.\n\n#### `storage._open(req)`\n\nImplement storage open.\n\nCall `req.callback` when it is fully opened.\n\n#### `storage._openReadonly(req)`\n\nImplement storage readonly open.\n\nUseful if you prefer to open the storage in readonly mode unless a write is performed. Call `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 as 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.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.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.destroy([callback])`\n\nDestroy the storage instance, removing all underlying data.\n\n#### `storage._destroy(req)`\n\nImplement storage destroy.\n\nCall `req.callback(err)` when the storage has been fully destroyed.\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","_attachments":{},"homepage":"https://github.com/random-access-storage/random-access-storage","bugs":{"url":"https://github.com/random-access-storage/random-access-storage/issues"},"license":"MIT"}