sonic-boom
Advanced tools
Comparing version 1.0.1 to 1.0.2
16
index.js
@@ -23,3 +23,7 @@ 'use strict' | ||
sonic.file = file | ||
fs.open(file, 'a', (err, fd) => { | ||
// NOTE: 'error' and 'ready' events emitted below only relevant when sonic.sync===false | ||
// for sync mode, there is no way to add a listener that will receive these | ||
function fileOpened (err, fd) { | ||
if (err) { | ||
@@ -46,3 +50,11 @@ sonic.emit('error', err) | ||
} | ||
}) | ||
} | ||
if (sonic.sync) { | ||
const fd = fs.openSync(file, 'a') | ||
fileOpened(null, fd) | ||
process.nextTick(() => sonic.emit('ready')) | ||
} else { | ||
fs.open(file, 'a', fileOpened) | ||
} | ||
} | ||
@@ -49,0 +61,0 @@ |
{ | ||
"name": "sonic-boom", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Extremely fast utf8 only stream implementation", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -60,3 +60,5 @@ # sonic-boom ![Node.js CI](https://github.com/mcollina/sonic-boom/workflows/Node.js%20CI/badge.svg) | ||
A `SonicBoom` instance will emit the `'ready'` event when a file descriptor is available. | ||
For `sync:false` a `SonicBoom` instance will emit the `'ready'` event when a file descriptor is available. | ||
For `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. | ||
@@ -94,3 +96,3 @@ ### SonicBoom#write(string) | ||
### SonicBook#destroy() | ||
### SonicBoom#destroy() | ||
@@ -97,0 +99,0 @@ Closes the stream immediately, the data is not flushed. |
11
test.js
@@ -763,1 +763,12 @@ 'use strict' | ||
}) | ||
// for context see this issue https://github.com/pinojs/pino/issues/871 | ||
test('file specified by dest path available immediately when options.sync is true', (t) => { | ||
t.plan(3) | ||
const dest = file() | ||
const stream = new SonicBoom({ dest, sync: true }) | ||
t.ok(stream.write('hello world\n')) | ||
t.ok(stream.write('something else\n')) | ||
stream.flushSync() | ||
t.pass('file opened and written to without error') | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32442
998
102