{"id":26648098,"url":"https://github.com/mcollina/sonic-boom","last_synced_at":"2025-03-25T00:01:48.769Z","repository":{"id":36985580,"uuid":"114138022","full_name":"pinojs/sonic-boom","owner":"pinojs","description":"Extremely fast utf8 only stream implementation","archived":false,"fork":false,"pushed_at":"2024-10-21T01:54:04.000Z","size":292,"stargazers_count":266,"open_issues_count":14,"forks_count":41,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-29T20:37:41.365Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pinojs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-13T15:36:04.000Z","updated_at":"2024-10-23T09:43:32.000Z","dependencies_parsed_at":"2024-01-13T22:24:55.696Z","dependency_job_id":"c914a9f5-3497-4be1-bcc7-af6fd6618321","html_url":"https://github.com/pinojs/sonic-boom","commit_stats":{"total_commits":252,"total_committers":29,"mean_commits":8.689655172413794,"dds":"0.49603174603174605","last_synced_commit":"049b199853eee2f99345021731c82399a5b558b2"},"previous_names":["mcollina/sonic-boom"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinojs%2Fsonic-boom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinojs%2Fsonic-boom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinojs%2Fsonic-boom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinojs%2Fsonic-boom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pinojs","download_url":"https://codeload.github.com/pinojs/sonic-boom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245372377,"owners_count":20604491,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-25T00:01:21.374Z","updated_at":"2025-03-25T00:01:48.725Z","avatar_url":"https://github.com/pinojs.png","language":"JavaScript","funding_links":[],"categories":["Packages"],"sub_categories":["Others"],"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/CI/badge.svg)](https://github.com/pinojs/sonic-boom/actions?query=workflow%3ACI)\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 \u003c 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\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([cb])\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\ncall the callback when the flush operation is completed. when failed the callback is called with an error.\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### Events\n\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 \u003cany\u003e\n\nWhen destination file maximal length is reached, the `'drop'` event is emitted with data that could not be written. \n\n#### SonicBoom#error \u003cError\u003e\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 \u003cnumber\u003e\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcollina%2Fsonic-boom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcollina%2Fsonic-boom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcollina%2Fsonic-boom/lists"}