forked from qawemlilo/node-streams
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream.js
More file actions
39 lines (29 loc) · 735 Bytes
/
stream.js
File metadata and controls
39 lines (29 loc) · 735 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
var fs = require('fs'),
files = fs.readdirSync('./files'),
clips = [],
stream,
currentfile,
dhh = fs.createWriteStream('./dhh-interview.mp3');
// create an array with filenames (time)
files.forEach(function (file) {
clips.push(file.substring(0, 6));
});
// Sort
clips.sort(function (a, b) {
return a - b;
});
// recursive function
function main() {
if (!clips.length) {
dhh.end("Done");
return;
}
currentfile = './files/' + clips.shift() + '.mp3';
stream = fs.createReadStream(currentfile);
stream.pipe(dhh, {end: false});
stream.on("end", function() {
console.log(currentfile + ' appended');
main();
});
}
main();