Node-Red configuration
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.

encoding-async 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env node
  2. var fs = require("fs"),
  3. queue = require("d3-queue").queue,
  4. rw = require("../");
  5. var code = 0;
  6. queue(1)
  7. .defer(testRead, "utf8", "gréén\n")
  8. .defer(testRead, {encoding: "utf8"}, "gréén\n")
  9. .defer(testRead, "ascii", "grC)C)n\n")
  10. .defer(testRead, {encoding: "ascii"}, "grC)C)n\n")
  11. .defer(testWrite, "utf8", "gréén\n")
  12. .defer(testWrite, {encoding: "utf8"}, "gréén\n")
  13. .defer(testWrite, "ascii", "gr��n\n")
  14. .defer(testWrite, {encoding: "ascii"}, "gr��n\n")
  15. .await(done);
  16. function testRead(options, expected, callback) {
  17. rw.readFile("test/utf8.txt", options, function(error, actual) {
  18. if (error) return void callback(error);
  19. if (actual !== expected) console.warn(actual + " !== " + expected), code = 1;
  20. callback(null);
  21. });
  22. }
  23. function testWrite(options, expected, callback) {
  24. rw.writeFile("test/encoding-async.out", "gréén\n", options, function(error) {
  25. if (error) return void callback(error);
  26. fs.readFile("test/encoding-async.out", "utf8", function(error, actual) {
  27. if (error) return void callback(error);
  28. if (actual !== expected) console.warn(actual + " !== " + expected), code = 1;
  29. callback(null);
  30. });
  31. });
  32. }
  33. function done(error) {
  34. if (error) throw error;
  35. process.exit(code);
  36. }