{"name":"random-access-file","version":"4.1.2","description":"Continuous reading or writing to a file using random offsets and lengths","main":"index.js","scripts":{"test":"standard && brittle test/*.js"},"browser":"./browser.js","imports":{"fs":{"bare":"bare-fs","default":"fs"},"path":{"bare":"bare-path","default":"path"}},"dependencies":{"bare-fs":"^4.0.1","bare-path":"^3.0.0","random-access-storage":"^3.0.0"},"optionalDependencies":{"fs-native-extensions":"^1.3.1"},"devDependencies":{"brittle":"^3.3.0","standard":"^17.0.0"},"repository":{"type":"git","url":"git+https://github.com/random-access-storage/random-access-file.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"MIT","bugs":{"url":"https://github.com/random-access-storage/random-access-file/issues"},"homepage":"https://github.com/random-access-storage/random-access-file","_id":"random-access-file@4.1.2","gitHead":"f2ea5a81051483844997e236b3171502d9d96c35","_nodeVersion":"20.11.1","_npmVersion":"10.9.1","dist":{"integrity":"sha512-GQM6R78DceZDcQod8KxlDFwXIiUvlvuy1EOzxTDsjuDjW5NlnlZi0MOk6iI4itAj/2vcvdqcEExYbVpC/dJcEw==","shasum":"7311a2737760b099bba29a0393f4cf60dbf490d2","tarball":"http://registry-npm.ywwl.com/random-access-file/download/random-access-file-4.1.2.tgz","fileCount":4,"unpackedSize":9742,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA9yrMdsQt3Go1UGCWwJ/uD4X0Y7GoM+lCPwwUBn9eqIAiEA0CyWvJhB7V3KsVWS68DmLwFPR9jcUTv566IknQxSvXk="}],"size":3294,"noattachment":false,"key":"/random-access-file/-/random-access-file-4.1.2.tgz"},"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/random-access-file_4.1.2_1734685885319_0.39929592784212886"},"_hasShrinkwrap":false,"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":1734685885503,"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"_cnpm_publish_time":1734685885503,"dist-tags":{"latest":"4.1.2"}}