{"name":"sonic-boom","version":"2.4.2","description":"Extremely fast utf8 only stream implementation","main":"index.js","type":"commonjs","types":"types/index.d.ts","scripts":{"test":"npm run test:types && standard && tap test.js","test:unit":"tap test.js","test:types":"tsc && tsd && ts-node types/tests/test.ts","prepare":"husky install"},"repository":{"type":"git","url":"git+https://github.com/pinojs/sonic-boom.git"},"keywords":["stream","fs","net","fd","file","descriptor","fast"],"author":{"name":"Matteo Collina","email":"hello@matteocollina.com"},"license":"MIT","bugs":{"url":"https://github.com/pinojs/sonic-boom/issues"},"homepage":"https://github.com/pinojs/sonic-boom#readme","devDependencies":{"@types/node":"^17.0.0","fastbench":"^1.0.1","husky":"^7.0.1","proxyquire":"^2.1.0","standard":"^16.0.3","tap":"^15.1.5","tsd":"^0.19.0","typescript":"^4.5.2","ts-node":"^10.4.0"},"dependencies":{"atomic-sleep":"^1.0.0"},"husky":{"hooks":{"pre-commit":"npm test"}},"tsd":{"directory":"./types"},"readme":"# sonic-boom\n\n[![NPM Package Version](https://img.shields.io/npm/v/sonic-boom)](https://www.npmjs.com/package/sonic-boom)\n[![Build Status](https://github.com/pinojs/sonic-boom/workflows/Node.js%20CI/badge.svg)](https://github.com/pinojs/sonic-boom/actions?query=workflow%3ANode.js%20CI)\n[![Known Vulnerabilities](https://snyk.io/test/github/pinojs/sonic-boom/badge.svg)](https://snyk.io/test/github/pinojs/sonic-boom)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)\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* `sync`: perform writes synchronously (similar to `console.log`).\n* `append`: appends writes to dest file instead of truncating it (default `true`).\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 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\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\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()\n\nWrites the current buffer to the file if a write was not in progress.\nDo nothing if `minLength` is zero or if it is already writing.\n\n### SonicBoom#reopen([file])\n\nReopen the file in place, useful for log rotation.\n\nExample:\n\n```js\nconst stream = new SonicBoom('./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\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\n## License\n\nMIT\n","readmeFilename":"README.md","gitHead":"0f0508b33e11888658b65f64c31fea8fdf8528b0","_id":"sonic-boom@2.4.2","_nodeVersion":"16.13.0","_npmVersion":"8.1.0","dist":{"integrity":"sha512-zlOmAKFLJzTI+MbvmkWhnOOJ++NYo0Iy7F93ARNPmvZvpWG2l8Ff3uwM3CkpHqRw8v3pcRROScM5E+vbeTeOKw==","shasum":"34c0965b1a498abedaaca794c752d190f74b5e8f","tarball":"http://registry-npm.ywwl.com/sonic-boom/download/sonic-boom-2.4.2.tgz","fileCount":14,"unpackedSize":52892,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhyaloCRA9TVsSAnZWagAAA6AQAJEheHFnTqbmd1o7xgrj\nkS55HEa5xXW3XlnljuzDllhyqrOL+zE53TKJIEo3Ynsadk2x8t3HSRjIC9bu\nlRKUzG8/WSXYX4US15yQvxAUUqBXMmldhjJV2KZiYFwZI+cfpztZH3UIVQpw\nXYm5hw+VqibvyMdArPjMWIndBh0WZzY0K3wkxAwh5E3Z1THzJcU43v3tsrg4\nVMXLUoF1/tY/GwHawvLApd/05TFdkw7qxw7DDm45DwdK+YEjcH5Fe5zNbArb\n4UsuE3YyP9eQG5sW7odSoepch9efvded3j+BuQDtHb1qquwxQt2HV/RYcqNe\nd9Yqo7wI36eFnqeEAqGTnZzy27iC0HfkEoCjQCw3uj6OMmIu91j7H1PNRwmC\nf/Fw4zF4hGAKKeDgJV461nb6+1IqWV1O3k4VtS6MskbXtcOP2bYprFP34lMs\nsXld+0RB5zE2b++8HMOB2+WLFAyYK2ZR4mSNkQJn38cXtky+7uoSjIoK46PN\nKDJ9IFOqNAmB8Mdg+DAhBv/+TeUbuF3IWeYf7itmmFisE1ShRCyl300cybDo\nqgl46ALCulA7GxwrTymnDu4411DO+kjnoKsNhxcFdMmR9N9YpZA/hC7DEqoP\nUargQbbRy66moG2uZ+ffJSuyWj1IAlB23cjEx/86kBHQGjsiDParZXq8xgTG\nhPYn\r\n=RfDa\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDV76dfZfmgb4DUWa4K5GHyG5tHT4U248JhWNBxyNZyegIhAOvX/BrIMIWZW8QKRSRFg6+SgF9dKcxjAmmpgsOjTems"}],"size":10548,"noattachment":false,"key":"/sonic-boom/-/sonic-boom-2.4.2.tgz"},"_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"directories":{},"maintainers":[{"name":"davidmarkclements","email":"david.mark.clements@gmail.com"},{"name":"matteo.collina","email":"hello@matteocollina.com"},{"name":"jsumners","email":"james.sumners@gmail.com"},{"name":"watson","email":"w@tson.dk"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sonic-boom_2.4.2_1640606056073_0.9457029554628424"},"_hasShrinkwrap":false,"publish_time":1640606056234,"_cnpm_publish_time":1640606056234,"dist-tags":{"four":"2.4.2","latest":"5.0.2"}}