02-stream.js 628 B

1234567891011121314151617181920212223
  1. var helper = require("./test-helper.js"),
  2. Stream = require("..").WritableStream,
  3. fs = require("fs"),
  4. path = require("path");
  5. helper.mochaTest("Stream", __dirname, function(test, cb){
  6. var filePath = path.join(__dirname, "Documents", test.file);
  7. fs.createReadStream(filePath).pipe(
  8. new Stream(
  9. helper.getEventCollector(function(err, events){
  10. cb(err, events);
  11. var handler = helper.getEventCollector(cb),
  12. stream = new Stream(handler, test.options);
  13. fs.readFile(filePath, function(err, data){
  14. if(err) throw err;
  15. else stream.end(data);
  16. });
  17. }
  18. ), test.options)
  19. ).on("error", cb);
  20. });