-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreams.js
72 lines (60 loc) · 1.62 KB
/
streams.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*!
* coone <https://github.com/hybridables/coone>
*
* Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/
'use strict'
var fs = require('fs')
var path = require('path')
var coone = require('../index')
var filepath = path.join(path.dirname(__dirname), 'package.json')
/**
* sync function which accept arguments and retun
* successful fs.createReadStream
* @todo in merz/always-done/always-callback to read the stream contents
*/
coone(function (fp) {
return fs.createReadStream(fp)
}, filepath)(function (err, res) {
if (err) return console.error(err)
console.log(res) // => undefined
})
/**
* pure sync function that return
* successful fs.createReadStream
* @todo in merz/always-done/always-callback to read the stream contents
*/
coone(function () {
return fs.createReadStream(filepath)
})(function (err, res) {
if (err) return console.error(err)
console.log(res) // => undefined
})
/**
* directly passed stream to coone function
* using the fs.createReadStream
*/
coone(fs.createReadStream(filepath))(function (err, res) {
if (err) return console.error(err)
console.log(res) // => undefined
})
/**
* failing stream
* just giving `fs.createReadStream` function
* to coone function
*/
coone(fs.createReadStream, 'foobar.json')(function (err, res) {
if (err) {
console.error(err.code) // => 'ENOENT'
return
}
console.log(res) // => undefined
})
/**
* coone `fs.createReadStream` function
*/
coone(fs.createReadStream, filepath)(function (err, res) {
if (err) return console.error(err)
console.log(res) // => undefined
})