index.js
1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use strict";
module.exports = make
module.exports.ctor = ctor
module.exports.obj = obj
module.exports.objCtor = objCtor
var through2 = require("through2")
var xtend = require("xtend")
function ctor(options, fn) {
if (typeof options == "function") {
fn = options
options = {}
}
return through2.ctor(options, function (chunk, encoding, callback) {
if (this.options.wantStrings) chunk = chunk.toString()
var err = fn.call(this, chunk, encoding)
if (err instanceof Error) return callback(err)
return callback(null)
})
}
function objCtor(options, fn) {
if (typeof options === "function") {
fn = options
options = {}
}
options = xtend({objectMode: true, highWaterMark: 16}, options)
return ctor(options, fn)
}
function make(options, fn) {
return ctor(options, fn)()
}
function obj(options, fn) {
if (typeof options === "function") {
fn = options
options = {}
}
options = xtend({objectMode: true, highWaterMark: 16}, options)
return make(options, fn)
}