{"_id":"sonic-boom@5.0.2","tsd":{"directory":"./types"},"bugs":{"url":"https://github.com/pinojs/sonic-boom/issues"},"dist":{"shasum":"a2ce0c7c70e71f5ef1d5511f67063b0bbaf41705","tarball":"http://registry-npm.ywwl.com/sonic-boom/download/sonic-boom-5.0.2.tgz","fileCount":26,"integrity":"sha512-/JEruzo6yhNVhsLblTRchgTQHIt7SsdJP0YyrfWaNKjIOQDfrdZv9gwYraYCAsmKV39/LAdV31FLL5NCDpoL/A==","signatures":[{"sig":"MEUCIAnE2UOPfhoXdHmg85kp+Qh3g5vmL2FFSqyfm2XHwWAvAiEA0eBG4dfWB+AHpL4cwflkylDlOLHJM091H6Skaf2e2us=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDJ302W7gOZBmvorVRIEzd77jqeQ4ODQQC4wALdXc6xygIgGNIxoFlTdJNS5FFbvK/FnKValS4ZkuwaepvkdgmkROg="}],"unpackedSize":123700,"size":23309,"noattachment":false,"key":"/sonic-boom/-/sonic-boom-5.0.2.tgz"},"main":"index.js","name":"sonic-boom","type":"commonjs","types":"types/index.d.ts","author":{"name":"Matteo Collina","email":"hello@matteocollina.com"},"gitHead":"8595727c93d9f2ca78b366d19e22e27c2c8fb82f","license":"MIT","scripts":{"lint":"eslint .","test":"npm run test:types && npm run lint && npm run test:unit","lint:fix":"eslint --fix .","test:unit":"borp --timeout=240000 'test/*.test.js'","test:types":"tsc && tsd"},"version":"5.0.2","_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"homepage":"https://github.com/pinojs/sonic-boom#readme","keywords":["stream","fs","net","fd","file","descriptor","fast"],"repository":{"url":"git+https://github.com/pinojs/sonic-boom.git","type":"git"},"_npmVersion":"11.19.0","description":"Extremely fast utf8 only stream implementation","directories":{},"maintainers":[{"name":"matteo.collina","email":"hello@matteocollina.com"},{"name":"jsumners","email":"james.sumners@gmail.com"}],"_nodeVersion":"24.21.0","dependencies":{"atomic-sleep":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"tsd":"^0.33.0","borp":"^1.0.0","eslint":"^9.39.4","fastbench":"^1.0.1","proxyquire":"^2.1.3","typescript":"~7.0.2","@types/node":"^26.0.1","neostandard":"^0.13.0","@sinonjs/fake-timers":"^15.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sonic-boom_5.0.2_1791378056683_0.6949494183995137"},"readme":"# sonic-boom\n\nExtremely fast utf8-only stream implementation to write to files and\nfile descriptors.\n\nThis implementation is partial, but support backpressure and `.pipe()` in is here.\nHowever, it is 2-3x faster than Node Core `fs.createWriteStream()`:\n\n```\nbenchSonic*1000: 1916.904ms\nbenchSonicSync*1000: 8605.265ms\nbenchSonic4k*1000: 1965.231ms\nbenchSonicSync4k*1000: 1588.224ms\nbenchCore*1000: 5851.959ms\nbenchConsole*1000: 7605.713ms\n```\n\nNote that sync mode without buffering is _slower_ than a Node Core WritableStream, however\nthis mode matches the expected behavior of `console.log()`.\n\nNote that if this is used to log to a windows terminal (`cmd.exe` or\npowershell), it is needed to run `chcp 65001` in the terminal to\ncorrectly display utf-8 characters, see\n[chcp](https://ss64.com/nt/chcp.html) for more details.\n\n## Install\n\n```\nnpm i sonic-boom\n```\n\n## Example\n\n```js\n'use strict'\n\nconst SonicBoom = require('sonic-boom')\nconst sonic = new SonicBoom({ fd: process.stdout.fd }) // or { dest: '/path/to/destination' }\n\nfor (let i = 0; i < 10; i++) {\n  sonic.write('hello sonic\\n')\n}\n```\n\n## API\n\n### SonicBoom(opts)\n\nCreates a new instance of SonicBoom.\n\nThe options are:\n\n* `fd`: a file descriptor, something that is returned by `fs.open` or\n   `fs.openSync`.\n* `dest`: a string that is a path to a file to be written to (mode controlled by the `append` option).\n* `minLength`: the minimum length of the internal buffer that is\n  required to be full before flushing.\n* `maxLength`: the maximum length of the internal buffer. If a write operation would cause the buffer\n  to exceed `maxLength`, the data written is dropped and a `drop` event is emitted with the dropped data\n* `maxWrite`: the maximum number of bytes that can be written; default: 16384\n* `periodicFlush`: calls `flush` every x`ms`.\n* `sync`: perform writes synchronously (similar to `console.log`).\n* `fsync`: perform a [fsyncSync](https://nodejs.org/api/fs.html#fsfsyncsyncfd) every time a write is completed.\n* `append`: appends writes to dest file instead of truncating it (default `true`).\n* `mode`: specify the creating file `mode` (see [fs.open()](https://nodejs.org/api/fs.html#fsopenpath-flags-mode-callback) from Node.js core).\n* `contentMode`: which type of data you can send to the `write` function, supported values are `utf8` or `buffer`. (default `utf8`)\n* `mkdir`: ensure directory for dest file exists when `true` (default `false`).\n* `retryEAGAIN(err, writeBufferLen, remainingBufferLen)`: a function that will be called when sonic-boom\n    write/writeSync/flushSync encounters a EAGAIN or EBUSY error. If the return value is\n    true sonic-boom will retry the operation, otherwise it will bubble the\n    error. `err` is the error that caused this function to be called,\n    `writeBufferLen` is the length of the buffer sonic-boom tried to write, and\n    `remainingBufferLen` is the length of the remaining buffer sonic-boom didn't try to write.\n* `maxWriteRetries`: the maximum number of *consecutive* EAGAIN/EBUSY retries\n    (across `write`, `writeSync` and `flushSync`) sonic-boom will attempt\n    before giving up and emitting/throwing the error, instead of retrying\n    forever. The counter resets on every successful write. Default: `0`\n    (no limit - preserves the previous unbounded-retry behavior). Set this if\n    the destination can become permanently unwritable (e.g. a reader that\n    stops draining a pipe), to avoid unbounded growth of the internal write\n    buffer while retries are silently attempted forever - see\n    [#65](https://github.com/pinojs/sonic-boom/issues/65).\n\nFor `sync:false`  a `SonicBoom` instance will emit the `'ready'` event when a file descriptor is available.\nFor `sync:true` this is not relevant because the `'ready'` event will be fired when the `SonicBoom` instance is created, before it can be subscribed to.\n\n### SonicBoom#write(string)\n\nWrites the string to the file.\nIt will return false to signal the producer to slow down.\n\n### SonicBoom#flush([cb])\n\nWrites the current buffer to the file. If a write is already in progress,\nthe buffered data is written after it completes.\n\nThe callback is called once all pending writes have completed and the file\nhas been fsynced (unless the `fsync` option is set). fsync errors meaning the\nfile descriptor cannot be synchronized, such as a pipe or TTY, are ignored.\nIf the flush fails, or the stream is destroyed before the data is flushed,\nthe callback is called with an error. `end()` waits for pending flushes\nbefore closing the stream.\n\n### SonicBoom#reopen([file])\n\nReopen the file in place, useful for log rotation.\n\nExample:\n\n```js\nconst stream = new SonicBoom({ dest: './my.log' })\nprocess.on('SIGUSR2', function () {\n  stream.reopen()\n})\n```\n\n### SonicBoom#flushSync()\n\nFlushes the buffered data synchronously. This is a costly operation.\n\nIf an asynchronous write is in flight when `flushSync()` is called, only the\ndata queued after it is written, and it may reach the file before the data\nof the in-flight write.\n\n### SonicBoom#end()\n\nCloses the stream, the data will be flushed down asynchronously\n\n### SonicBoom#destroy()\n\nCloses the stream immediately, the data is not flushed.\n\nIf the file is still being opened, the stream is marked as destroyed right\naway (so `write()` and `end()` throw) and is closed once the file is open.\nA pending `flush()` then fails with an `'error'` event.\n\n### Events\n\n#### SonicBoom#close\n\nSee [Stream#close](https://nodejs.org/api/stream.html#event-close). The `'close'` event when the instance has been closed.\n\n#### SonicBoom#drain\n\nSee [Stream#drain](https://nodejs.org/api/stream.html#event-drain). The `'drain'` event is emitted when source can resume sending data.\n\n#### SonicBoom#drop <any>\n\nWhen destination file maximal length is reached, the `'drop'` event is emitted with data that could not be written.\n\n#### SonicBoom#error <Error>\n\nThe `'error'` event is emitted when the destination file can not be opened, or written.\n\n#### SonicBoom#finish\n\nSee [Stream#finish](https://nodejs.org/api/stream.html#event-finish). The `'finish'` event after calling `end()` method and when all data was written.\n\n#### SonicBoom#ready\n\nThe `'ready'` event occurs when the created instance is ready to process input.\n\n#### SonicBoom#write <number>\n\nThe `'write'` event occurs every time data is written to the underlying file. It emits the number of written bytes.\n\n## License\n\nMIT\n","publish_time":1791378056772,"_cnpm_publish_time":1791378056772,"dist-tags":{"four":"2.4.2","latest":"5.0.2"}}