it-goodbye
Advanced tools
Comparing version 1.0.0 to 2.0.0
15
index.js
const endable = require('./endable') | ||
module.exports = (stream, goodbye) => { | ||
goodbye = goodbye || 'GOODBYE' | ||
goodbye = Buffer.from(goodbye || 'GOODBYE') | ||
const e = endable(goodbye) | ||
@@ -15,4 +15,13 @@ | ||
for await (const chunk of source) { | ||
if (chunk !== goodbye) yield chunk | ||
e.end() | ||
const buff = Buffer.from(chunk) | ||
const done = buff.slice(-goodbye.length).equals(goodbye) | ||
if (done) { | ||
const remaining = buff.length - goodbye.length | ||
if (remaining > 0) { | ||
yield buff.slice(0, remaining) | ||
} | ||
e.end() | ||
} else { | ||
yield buff | ||
} | ||
} | ||
@@ -19,0 +28,0 @@ })()) |
{ | ||
"name": "it-goodbye", | ||
"description": "Add a goodbye handshake to a duplex async iterable", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/alanshaw/it-goodbye", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -24,3 +24,2 @@ # it-goodbye | ||
var goodbye = require('it-goodbye') | ||
var serializer = require('it-serializer') | ||
@@ -30,3 +29,3 @@ // a duplex stream from somewhere... | ||
return serializer(goodbye(duplex, 'GoodBye')) | ||
return goodbye(duplex, 'GoodBye') | ||
``` | ||
@@ -33,0 +32,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5735
107
34