Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fs_test.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var stream = require('../lib/lazystream');
  2. var fs = require('fs');
  3. var tmpDir = 'test/tmp/';
  4. var readFile = 'test/data.md';
  5. var writeFile = tmpDir + 'data.md';
  6. exports.fs = {
  7. readwrite: function(test) {
  8. var readfd, writefd;
  9. var readable = new stream.Readable(function() {
  10. return fs.createReadStream(readFile)
  11. .on('open', function(fd) {
  12. readfd = fd;
  13. })
  14. .on('close', function() {
  15. readfd = undefined;
  16. step();
  17. });
  18. });
  19. var writable = new stream.Writable(function() {
  20. return fs.createWriteStream(writeFile)
  21. .on('open', function(fd) {
  22. writefd = fd;
  23. })
  24. .on('close', function() {
  25. writefd = undefined;
  26. step();
  27. });
  28. });
  29. test.expect(3);
  30. test.equal(readfd, undefined, 'Input file should not be opened until read');
  31. test.equal(writefd, undefined, 'Output file should not be opened until write');
  32. if (!fs.existsSync(tmpDir)) {
  33. fs.mkdirSync(tmpDir);
  34. }
  35. if (fs.existsSync(writeFile)) {
  36. fs.unlinkSync(writeFile);
  37. }
  38. readable.on('end', function() { step(); });
  39. writable.on('end', function() { step(); });
  40. var steps = 0;
  41. function step() {
  42. steps += 1;
  43. if (steps == 4) {
  44. var input = fs.readFileSync(readFile);
  45. var output = fs.readFileSync(writeFile);
  46. test.ok(input >= output && input <= output, 'Should be equal');
  47. fs.unlinkSync(writeFile);
  48. fs.rmdirSync(tmpDir);
  49. test.done();
  50. }
  51. };
  52. readable.pipe(writable);
  53. }
  54. };