Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to node 12 #50

Merged
merged 4 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,12 @@ name: ci
on: [push, pull_request]

jobs:
legacy:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [6.x, 8.x]

steps:
- uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install
run: |
npm install

- name: Run tests
run: |
npm run legacy

test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 12.x, 13.x, 14.x]
node-version: [12.x, 14.x, 16.x]

steps:
- uses: actions/checkout@v2
Expand Down
16 changes: 2 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Break up a stream and reassemble it so that each line is a chunk.
`split2` is inspired by [@dominictarr](https://github.com/dominictarr) [`split`](https://github.com/dominictarr/split) module,
and it is totally API compatible with it.
However, it is based on Node.js core [`Transform`](https://nodejs.org/api/stream.html#stream_new_stream_transform_options) via [`readable-stream`](https://github.com/nodejs/readable-stream)
However, it is based on Node.js core [`Transform`](https://nodejs.org/api/stream.html#stream_new_stream_transform_options).

`matcher` may be a `String`, or a `RegExp`. Example, read every line in a file ...

Expand Down Expand Up @@ -68,21 +68,9 @@ fs.createReadStream(file)
However, in [@dominictarr](https://github.com/dominictarr) [`split`](https://github.com/dominictarr/split) the mapper
is wrapped in a try-catch, while here it is not: if your parsing logic can throw, wrap it yourself. Otherwise, you can also use the stream error handling when mapper function throw.

# Benchmark

```bash
$ node bench.js
benchSplit*10000: 1484.983ms
benchBinarySplit*10000: 1484.080ms
benchSplit*10000: 1407.334ms
benchBinarySplit*10000: 1500.281ms
```

Benchmark taken on Node 8.11.3, on a Macbook i5 2018.

# License

Copyright (c) 2014-2018, Matteo Collina <[email protected]>
Copyright (c) 2014-2021, Matteo Collina <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
10 changes: 5 additions & 5 deletions bench.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

var split = require('./')
var bench = require('fastbench')
var binarySplit = require('binary-split')
var fs = require('fs')
const split = require('./')
const bench = require('fastbench')
const binarySplit = require('binary-split')
const fs = require('fs')

function benchSplit (cb) {
fs.createReadStream('package.json')
Expand All @@ -19,7 +19,7 @@ function benchBinarySplit (cb) {
.resume()
}

var run = bench([
const run = bench([
benchSplit,
benchBinarySplit
], 10000)
Expand Down
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2014-2018, Matteo Collina <[email protected]>
Copyright (c) 2014-2021, Matteo Collina <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand All @@ -16,15 +16,15 @@ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

'use strict'

const { Transform } = require('readable-stream')
const { Transform } = require('stream')
const { StringDecoder } = require('string_decoder')
const kLast = Symbol('last')
const kDecoder = Symbol('decoder')

function transform (chunk, enc, cb) {
var list
let list
if (this.overflow) { // Line buffer is full. Skip to start of next line.
var buf = this[kDecoder].write(chunk)
const buf = this[kDecoder].write(chunk)
list = buf.split(this.matcher)

if (list.length === 1) return cb() // Line ending not found. Discard entire chunk.
Expand All @@ -39,7 +39,7 @@ function transform (chunk, enc, cb) {

this[kLast] = list.pop()

for (var i = 0; i < list.length; i++) {
for (let i = 0; i < list.length; i++) {
try {
push(this, this.mapper(list[i]))
} catch (error) {
Expand Down Expand Up @@ -112,6 +112,7 @@ function split (matcher, mapper, options) {
}

options = Object.assign({}, options)
options.autoDestroy = true
options.transform = transform
options.flush = flush
options.readableObjectMode = true
Expand Down
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@
"fastbench": "^1.0.0",
"nyc": "^15.0.1",
"pre-commit": "^1.1.2",
"safe-buffer": "^5.1.1",
"standard": "^16.0.1",
"tape": "^5.0.0"
},
"dependencies": {
"readable-stream": "^3.0.0"
}
}
Loading