thread-stream 0.13.1 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js
CHANGED
|
@@ -110,7 +110,7 @@ function nextFlush (stream) {
|
|
|
110
110
|
// Find a toWrite length that fits the buffer
|
|
111
111
|
// it must exists as the buffer is at least 4 bytes length
|
|
112
112
|
// and the max utf-8 length for a char is 4 bytes.
|
|
113
|
-
while (toWriteBytes > stream[kImpl].
|
|
113
|
+
while (toWriteBytes > stream[kImpl].data.length) {
|
|
114
114
|
leftover = leftover / 2
|
|
115
115
|
toWrite = stream[kImpl].buf.slice(0, leftover)
|
|
116
116
|
toWriteBytes = Buffer.byteLength(toWrite)
|
package/package.json
CHANGED
|
@@ -49,3 +49,26 @@ test('break up utf8 multibyte (async)', (t) => {
|
|
|
49
49
|
stream.write(longString)
|
|
50
50
|
stream.end()
|
|
51
51
|
})
|
|
52
|
+
|
|
53
|
+
test('break up utf8 multibyte several times bigger than write buffer', (t) => {
|
|
54
|
+
t.plan(2)
|
|
55
|
+
const longString = '\u03A3'.repeat(32)
|
|
56
|
+
|
|
57
|
+
const dest = file()
|
|
58
|
+
const stream = new ThreadStream({
|
|
59
|
+
bufferSize: 15, // this must be odd
|
|
60
|
+
filename: join(import.meta.url, 'to-file.js'),
|
|
61
|
+
workerData: { dest },
|
|
62
|
+
sync: false
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
stream.on('finish', () => {
|
|
66
|
+
readFile(dest, 'utf8', (err, data) => {
|
|
67
|
+
t.error(err)
|
|
68
|
+
t.equal(data, longString)
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
stream.write(longString)
|
|
73
|
+
stream.end()
|
|
74
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const t = require('tap')
|
|
4
|
+
const { join } = require('path')
|
|
5
|
+
const { file } = require('./helper')
|
|
6
|
+
const { createReadStream } = require('fs')
|
|
7
|
+
const ThreadStream = require('..')
|
|
8
|
+
const buffer = require('buffer')
|
|
9
|
+
|
|
10
|
+
const MAX_STRING = buffer.constants.MAX_STRING_LENGTH
|
|
11
|
+
|
|
12
|
+
t.plan(1)
|
|
13
|
+
|
|
14
|
+
const dest = file()
|
|
15
|
+
const stream = new ThreadStream({
|
|
16
|
+
filename: join(__dirname, 'to-file.js'),
|
|
17
|
+
workerData: { dest },
|
|
18
|
+
sync: false
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
stream.on('close', async () => {
|
|
22
|
+
t.comment('close emitted')
|
|
23
|
+
let buf
|
|
24
|
+
for await (const chunk of createReadStream(dest)) {
|
|
25
|
+
buf = chunk
|
|
26
|
+
}
|
|
27
|
+
t.equal('asd', buf.toString().slice(-3))
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
stream.on('ready', () => {
|
|
31
|
+
t.comment('open emitted')
|
|
32
|
+
stream.write('a'.repeat(MAX_STRING - 2))
|
|
33
|
+
stream.write('asd')
|
|
34
|
+
stream.end()
|
|
35
|
+
})
|