Skip to content

Commit ecaf645

Browse files
lpincamourner
authored andcommitted
1 parent 1d0ff7b commit ecaf645

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ var os = require('os')
33

44
module.exports = BinarySplit
55

6-
function BinarySplit (matcher) {
7-
if (!(this instanceof BinarySplit)) return new BinarySplit(matcher)
8-
matcher = Buffer(matcher || os.EOL)
6+
function BinarySplit (splitOn) {
7+
if (!(this instanceof BinarySplit)) return new BinarySplit(splitOn)
8+
splitOn = splitOn || os.EOL
9+
var matcher = Buffer.from && Buffer.from !== Uint8Array.from
10+
? Buffer.from(splitOn)
11+
: new Buffer(splitOn)
912
var buffered
1013
return through(write, end)
1114

test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ var test = require('tape')
22
var fs = require('fs')
33
var split = require('./')
44

5+
var bufferFrom = Buffer.from && Buffer.from !== Uint8Array.from
6+
57
function splitTest (matcher, cb) {
68
if (!cb) {
79
cb = matcher
@@ -35,27 +37,31 @@ test('custom matcher', function (t) {
3537
t.equals(items.length, 5)
3638
t.equals(items.join(' '), 'hello yes this is dog')
3739
t.end()
40+
});
41+
42+
['hello yes ', 'this', ' is d', 'og'].map(function (chunk) {
43+
return bufferFrom ? Buffer.from(chunk) : new Buffer(chunk)
44+
}).forEach(function (chunk) {
45+
splitStream.write(chunk)
3846
})
39-
splitStream.write(new Buffer('hello yes '))
40-
splitStream.write(new Buffer('this'))
41-
splitStream.write(new Buffer(' is d'))
42-
splitStream.write(new Buffer('og'))
4347
splitStream.end()
4448
})
4549

4650
test('long matcher', function (t) {
51+
var data = 'hello yes this is dog'
4752
var splitStream = splitTest('this', function (err, items) {
4853
if (err) throw err
4954
t.equals(items.length, 2)
5055
t.equals(items[0].toString(), 'hello yes ')
5156
t.equals(items[1].toString(), ' is dog')
5257
t.end()
5358
})
54-
splitStream.write(new Buffer('hello yes this is dog'))
59+
splitStream.write(bufferFrom ? Buffer.from(data) : new Buffer(data))
5560
splitStream.end()
5661
})
5762

5863
test('matcher at index 0 check', function (t) {
64+
var data = '\nhello\nmax'
5965
var splitStream = splitTest(function (err, items) {
6066
if (err) throw err
6167

@@ -65,7 +71,7 @@ test('matcher at index 0 check', function (t) {
6571
t.end()
6672
})
6773

68-
splitStream.write(new Buffer('\nhello\nmax'))
74+
splitStream.write(bufferFrom ? Buffer.from(data) : new Buffer(data))
6975
splitStream.end()
7076
})
7177

0 commit comments

Comments
 (0)