Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/concat-stream.js')
-rw-r--r--lib/concat-stream.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/concat-stream.js b/lib/concat-stream.js
new file mode 100644
index 0000000..c2d8860
--- /dev/null
+++ b/lib/concat-stream.js
@@ -0,0 +1,14 @@
+module.exports = function (stream, cb) {
+ var chunks = []
+ stream.on('data', function (chunk) {
+ chunks.push(chunk)
+ })
+ stream.once('end', function () {
+ if (cb) cb(null, Buffer.concat(chunks))
+ cb = null
+ })
+ stream.once('error', function (err) {
+ if (cb) cb(err)
+ cb = null
+ })
+}