sonic-boom
Advanced tools
Comparing version 3.6.0 to 3.6.1
13
index.js
@@ -57,3 +57,3 @@ 'use strict' | ||
if (sonic._reopening) { | ||
if (sonic._reopening || sonic.destroyed) { | ||
return | ||
@@ -63,3 +63,3 @@ } | ||
// start | ||
if (!sonic._writing && sonic._len > sonic.minLength && !sonic.destroyed) { | ||
if ((!sonic._writing && sonic._len > sonic.minLength) || sonic._flushPending) { | ||
sonic._actualWrite() | ||
@@ -108,2 +108,3 @@ } | ||
this._asyncDrainScheduled = false | ||
this._flushPending = false | ||
this._hwm = Math.max(minLength || 0, 16387) | ||
@@ -343,7 +344,12 @@ this.file = null | ||
function callFlushCallbackOnDrain (cb) { | ||
this._flushPending = true | ||
const onDrain = () => { | ||
// only if _fsync is false to avoid double fsync | ||
if (!this._fsync) { | ||
fs.fsync(this.fd, cb) | ||
fs.fsync(this.fd, (err) => { | ||
this._flushPending = false | ||
cb(err) | ||
}) | ||
} else { | ||
this._flushPending = false | ||
cb() | ||
@@ -354,2 +360,3 @@ } | ||
const onError = (err) => { | ||
this._flushPending = false | ||
cb(err) | ||
@@ -356,0 +363,0 @@ this.off('drain', onDrain) |
{ | ||
"name": "sonic-boom", | ||
"version": "3.6.0", | ||
"version": "3.6.1", | ||
"description": "Extremely fast utf8 only stream implementation", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -376,2 +376,45 @@ 'use strict' | ||
}) | ||
test('call flush cb when writing and trying to flush before ready (on async)', (t) => { | ||
t.plan(4) | ||
const fakeFs = Object.create(fs) | ||
const SonicBoom = proxyquire('../', { | ||
fs: fakeFs | ||
}) | ||
fakeFs.open = fsOpen | ||
const dest = file() | ||
const stream = new SonicBoom({ | ||
fd: dest, | ||
// only async as sync is part of the constructor so the user will not be able to call write/flush | ||
// before ready | ||
sync: false, | ||
// to not trigger write without calling flush | ||
minLength: 4096 | ||
}) | ||
stream.on('ready', () => { | ||
t.pass('ready emitted') | ||
}) | ||
function fsOpen (...args) { | ||
process.nextTick(() => { | ||
// try writing and flushing before ready and in the middle of opening | ||
t.pass('fake fs.open called') | ||
t.ok(stream.write('hello world\n')) | ||
// calling flush | ||
stream.flush((err) => { | ||
if (err) t.fail(err) | ||
else t.pass('flush cb called') | ||
}) | ||
fakeFs.open = fs.open | ||
fs.open(...args) | ||
}) | ||
} | ||
}) | ||
} |
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
79915
2556