Skip to content

Commit ddd2de7

Browse files
committed
add (failing) test for #8
1 parent 5431ca4 commit ddd2de7

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,28 @@ function BinarySplit (matcher) {
1919
buf = bops.join([buffered, buf])
2020
buffered = undefined
2121
}
22+
console.error(buf, offset)
2223

2324
while (buf) {
2425
var idx = firstMatch(buf, offset)
2526
if (idx) {
26-
var line = bops.subarray(buf, offset, idx)
2727
if (idx === buf.length) {
28-
buffered = line
28+
console.error('idx === buf.length')
29+
buffered = buf
2930
buf = undefined
3031
offset = idx
3132
} else {
32-
this.push(line)
33-
offset = idx + matcher.length
33+
console.error('idx !== buf.length')
34+
this.push(bops.subarray(buf, 0, idx))
35+
buf = bops.subarray(buf, idx)
36+
offset = 0
3437
}
3538
} else if (idx === 0) {
3639
buf = bops.subarray(buf, offset + matcher.length)
3740
} else {
3841
if (offset >= buf.length) {
3942
buffered = undefined
40-
offset = 0
43+
// offset = 0
4144
} else {
4245
buffered = buf
4346
}

test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,15 @@ test('matcher at index 0 check', function (t) {
6565
splitStream.write(new Buffer('\nhello\nmax'))
6666
splitStream.end()
6767
})
68+
69+
test('chunked input', function (t) {
70+
fs.createReadStream('test.json')
71+
.pipe(split('\n'))
72+
.pipe(split('i'))
73+
.pipe(splitTest(':', function (err, items) {
74+
if (err) throw err
75+
console.error('...', err, items)
76+
t.equals(items.length, 4)
77+
t.end()
78+
}))
79+
})

0 commit comments

Comments
 (0)