{"name":"random-access-file","version":"4.1.0","author":{"url":"@mafintosh","name":"Mathias Buus"},"license":"MIT","_id":"random-access-file@4.1.0","homepage":"https://github.com/random-access-storage/random-access-file","bugs":{"url":"https://github.com/random-access-storage/random-access-file/issues"},"dist":{"shasum":"aa0bdadc3aaccdc065143c4d092836a8e08781d8","tarball":"http://registry-npm.ywwl.com/random-access-file/download/random-access-file-4.1.0.tgz","fileCount":4,"integrity":"sha512-n8uYXv1QXBLIekN6g8ycBqT/3aS955ku/8lTMcqn78EaVLegz/QTsVZoojArijhyZjLyYVHQ4Hu/BKj9G7v4eg==","signatures":[{"sig":"MEUCIQCm+jJdud9znPahOxdAtaDxgVSWPpWhRYYfKMXHrEnSbQIgeFT8Kg+ku/Zni95Tk38nAxC8kS+DTrTWdyUlLsX8HUk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9982,"size":3418,"noattachment":false,"key":"/random-access-file/-/random-access-file-4.1.0.tgz"},"main":"index.js","browser":"./browser.js","gitHead":"872e17e43d7f3f9eb6656438c63c4da8f540588b","imports":{"fs":{"bare":"bare-fs","default":"fs"},"path":{"bare":"bare-path","default":"path"}},"scripts":{"test":"standard && brittle test/*.js"},"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"repository":{"url":"git+https://github.com/random-access-storage/random-access-file.git","type":"git"},"_npmVersion":"10.7.0","description":"Continuous reading or writing to a file using random offsets and lengths","directories":{},"_nodeVersion":"20.11.1","dependencies":{"random-access-storage":"^3.0.0"},"_hasShrinkwrap":false,"devDependencies":{"brittle":"^3.3.0","standard":"^17.0.0"},"optionalDependencies":{"bare-fs":"^3.0.2","bare-path":"^3.0.0","fs-native-extensions":"^1.3.1"},"_npmOperationalInternal":{"tmp":"tmp/random-access-file_4.1.0_1728982917617_0.5987784143483883","host":"s3://npm-registry-packages"},"readme":"# random-access-file\n\nContinuous reading or writing to a file using random offsets and lengths\n\n```\nnpm install random-access-file\n```\n\n## Why?\n\nIf you are receiving a file in multiple pieces in a distributed system it can be useful to write these pieces to disk one by one in various places throughout the file without having to open and close a file descriptor all the time.\n\nrandom-access-file allows you to do just this.\n\n## Usage\n\n``` js\nconst RandomAccessFile = require('random-access-file')\n\nconst file = new RandomAccessFile('my-file.txt')\n\nfile.write(10, Buffer.from('hello'), function(err) {\n  // write a buffer to offset 10\n  file.read(10, 5, function(err, buffer) {\n    console.log(buffer) // read 5 bytes from offset 10\n    file.close(function() {\n      console.log('file is closed')\n    })\n  })\n})\n```\n\nfile will use an open file descriptor. When you are done with the file you should call `file.close()`.\n\n## API\n\n#### `const file = new RandomAccessFile(filename, [options])`\n\nCreate a new file. Options include:\n\n``` js\n{\n  truncate: false, // truncate the file before reading / writing\n  size: someSize, // truncate the file to this size first\n  readable: true, // should the file be opened as readable?\n  writable: true,  // should the file be opened as writable?\n  lock: false, // lock the file\n  sparse: false // mark the file as sparse\n}\n```\n\n#### `file.write(offset, buffer, [callback])`\n\nWrite a buffer at a specific offset.\n\n#### `file.read(offset, length, callback)`\n\nRead a buffer at a specific offset. Callback is called with the buffer read.\n\n#### `file.del(offset, length, callback)`\n\nDelete a portion of the file. Any partial file blocks in the deleted portion are zeroed and, if the file is sparse, the remaining file blocks unlinked in-place.\n\n#### `file.truncate(offset, callback)`\n\nTruncate the file length to this offset.\n\n#### `file.stat(callback)`\n\nStat the storage. Should return an object with useful information about the underlying storage, including:\n\n```js\n{\n  size: number // how many bytes of data is stored?\n}\n```\n\n#### `file.close([callback])`\n\nClose the underlying file descriptor.\n\n#### `file.unlink([callback])`\n\nUnlink the underlying file.\n\n#### `file.on('open')`\n\nEmitted when the file descriptor has been opened. You can access the fd using `file.fd`.\nYou do not need to wait for this event before doing any reads/writes.\n\n#### `file.on('close')`\n\nEmitted when the file has been closed.\n\n## License\n\nMIT\n","publish_time":1728982917775,"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"_cnpm_publish_time":1728982917775,"dist-tags":{"latest":"4.1.2"}}