sonic-boom
Advanced tools
Comparing version 3.1.0 to 3.2.0
12
index.js
@@ -158,2 +158,14 @@ 'use strict' | ||
this._len -= n | ||
// In case of multi-byte characters, the length of the written buffer | ||
// may be different from the length of the string. Let's make sure | ||
// we do not have an accumulated string with a negative length. | ||
// This also mean that ._len is not precise, but it's not a problem as some | ||
// writes might be triggered earlier than ._minLength. | ||
if (this._len < 0) { | ||
this._len = 0 | ||
} | ||
// TODO if we have a multi-byte character in the buffer, we need to | ||
// n might not be the same as this._writingBuf.length, so we might loose | ||
// characters here. The solution to this problem is to use a Buffer for _writingBuf. | ||
this._writingBuf = this._writingBuf.slice(n) | ||
@@ -160,0 +172,0 @@ |
{ | ||
"name": "sonic-boom", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Extremely fast utf8 only stream implementation", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
37
test.js
@@ -1648,1 +1648,38 @@ 'use strict' | ||
}) | ||
test('._len must always be equal or greater than 0', (t) => { | ||
t.plan(3) | ||
const dest = file() | ||
const fd = fs.openSync(dest, 'w') | ||
const stream = new SonicBoom({ fd, sync: true }) | ||
t.ok(stream.write('hello world 👀\n')) | ||
t.ok(stream.write('another line 👀\n')) | ||
t.equal(stream._len, 0) | ||
stream.end() | ||
}) | ||
test('._len must always be equal or greater than 0', (t) => { | ||
const n = 20 | ||
t.plan(n + 3) | ||
const dest = file() | ||
const fd = fs.openSync(dest, 'w') | ||
const stream = new SonicBoom({ fd, sync: true, minLength: 20 }) | ||
let str = '' | ||
for (let i = 0; i < 20; i++) { | ||
t.ok(stream.write('👀')) | ||
str += '👀' | ||
} | ||
t.equal(stream._len, 0) | ||
fs.readFile(dest, 'utf8', (err, data) => { | ||
t.error(err) | ||
t.equal(data, str) | ||
}) | ||
}) |
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
60405
1877