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.
@@ -23,7 +23,7 @@ jobs:
23
23
  with:
24
24
  node-version: ${{ matrix.node-version }}
25
25
  - name: Use pnpm
26
- uses: pnpm/action-setup@v2.0.1
26
+ uses: pnpm/action-setup@v2.2.1
27
27
  with:
28
28
  version: ^6.0.0
29
29
  - name: Install dependancies
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].buf.length) {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thread-stream",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "description": "A streaming way to send data to a Node.js Worker Thread",
5
5
  "main": "index.js",
6
6
  "dependencies": {
@@ -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
+ })