pax_global_header00006660000000000000000000000064130404424340014510gustar00rootroot0000000000000052 comment=59819802cb6718a44aad42bb75ccb4f93f6efad5 rw-1.3.3/000077500000000000000000000000001304044243400121445ustar00rootroot00000000000000rw-1.3.3/.eslintrc000066400000000000000000000000671304044243400137730ustar00rootroot00000000000000env: node: true extends: "eslint:recommended" rw-1.3.3/.gitignore000066400000000000000000000000461304044243400141340ustar00rootroot00000000000000.DS_Store node_modules test/input.txt rw-1.3.3/LICENSE000066400000000000000000000026251304044243400131560ustar00rootroot00000000000000Copyright (c) 2014-2016, Michael Bostock All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * The name Michael Bostock may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. rw-1.3.3/README.md000066400000000000000000000165431304044243400134340ustar00rootroot00000000000000# rw - Now stdin and stdout are files. How do you read a file from stdin? If you thought, ```js var contents = fs.readFileSync("/dev/stdin", "utf8"); ``` you’d be wrong, because Node only reads up to the size of the file reported by fs.stat rather than reading until it receives an EOF. So, if you redirect a file to your program (`cat file | program`), you’ll only read the first 65,536 bytes of your file. Oops. What about writing a file to stdout? If you thought, ```js fs.writeFileSync("/dev/stdout", contents, "utf8"); ``` you’d also be wrong, because this tries to close stdout, so you get this error: ``` Error: UNKNOWN, unknown error at Object.fs.writeSync (fs.js:528:18) at Object.fs.writeFileSync (fs.js:975:21) ``` (Also, this doesn’t work on Windows, because Windows doesn’t support /dev/stdout, /dev/stdin and /dev/stderr!) Shucks. So what should you do? You could use a different pattern for reading from stdin: ```js var chunks = []; process.stdin .on("data", function(chunk) { chunks.push(chunk); }) .on("end", function() { console.log(chunks.join("").length); }) .setEncoding("utf8"); ``` But that’s a pain, since now your code has two different code paths for reading inputs depending on whether you’re reading a real file or stdin. And the code gets even more complex if you want to [read that file synchronously](https://github.com/mbostock/rw/blob/master/lib/rw/read-file-sync.js). You could also try a different pattern for writing to stdout: ```js process.stdout.write(contents); ``` Or even: ```js console.log(contents); ``` But if you try to pipe your output to `head`, you’ll get this error: ``` Error: write EPIPE at errnoException (net.js:904:11) at Object.afterWrite (net.js:720:19) ``` Huh. The **rw** module fixes these problems. It provides an interface just like readFile, readFileSync, writeFile and writeFileSync, but with implementations that work the way you expect on stdin and stdout. If you use these methods on files other than /dev/stdin or /dev/stdout, they simply delegate to the fs methods, so you can trust that they behave identically to the methods you’re used to. For example, now you can read stdin synchronously like so: ```js var contents = rw.readFileSync("/dev/stdin", "utf8"); ``` Or to write to stdout: ```js rw.writeFileSync("/dev/stdout", contents, "utf8"); ``` And rw automatically squashes EPIPE errors, so you can pipe the output of your program to `head` and you won’t get a spurious stack trace. To install, `npm install rw`. ### Note If you want to read synchronously from stdin using [readFileSync](#readFileSync), you cannot also use process.stdin in the same program. Likewise, if you want to write synchronously to stdout or stderr using [writeFileSync](#writeFileSync), you cannot use process.stdout or process.stderr, respectively. (This includes using console.log and the like!) Failure to heed this warning may result in error: EAGAIN, resource temporarily unavailable. Unfortunately, it does not appear possible for this library to fix this issue automatically, so please use caution. Only the asynchronous methods [readFile](#readFile) and [writeFile](#writeFile) are supported on Windows. Node has no synchronous API for reading from process.[stdin](https://nodejs.org/api/process.html#process_process_stdin) or writing to process.[stdout](https://nodejs.org/api/process.html#process_process_stdout) or process.[stderr](https://nodejs.org/api/process.html#process_process_stderr), so you’re out of luck! ## API Reference # rw.readFile(path[, options], callback) Reads the file at the specified *path* completely into memory, invoking the specified *callback* once the data is available and the file is closed. The *callback* is invoked with two arguments: the *error* that occurred during read (hopefully null), and the read data. If *options* is a string, it specifies the encoding to use, in which case the read data will be a string; otherwise *options* is an object, and may specify encoding and flag properties. This method is a drop-in replacement for [fs.readFile](https://nodejs.org/api/fs.html#fs_fs_readfile_file_options_callback) and fixes the behavior of special files such as /dev/stdin. # rw.readFileSync(path[, options]) Reads the file at the specified *path* completely into memory, synchronously, returning the data. If an error occurred during read, this function throws an error instead. If *options* is a string, it specifies the encoding to use, in which case the read data will be a string; otherwise *options* is an object, and may specify encoding and flag properties. This method is a drop-in replacement for [fs.readFileSync](https://nodejs.org/api/fs.html#fs_fs_readfilesync_file_options) and fixes the behavior of special files such as /dev/stdin. # rw.writeFile(path, data[, options], callback) Writes the specified *data* (completely in memory) to a file at the specified *path*, invoking the specified *callback* once the data is completely written and the file is closed. The *callback* is invoked with a single argument: the *error* that occurred during write (hopefully null). If *options* is a string, it specifies the encoding to use, in which case the *data* must be a string; otherwise *options* is an object, and may specify encoding, mode and flag properties. This method is a drop-in replacement for [fs.writeFile](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback) and fixes the behavior of special files such as /dev/stdout. # rw.writeFileSync(path, data[, options]) Writes the specified *data* (completely in memory) to a file at the specified *path*, synchronously, returning once the data is completely written and the file is closed. Throws an *error* if one occurs during write. If *options* is a string, it specifies the encoding to use, in which case the *data* must be a string; otherwise *options* is an object, and may specify encoding, mode and flag properties. This method is a drop-in replacement for [fs.writeFileSync](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options) and fixes the behavior of special files such as /dev/stdout. # rw.dash.readFile(path[, options], callback) Equivalent to [rw.readFile](#readFile), except treats a *path* of `-` as `/dev/stdin`. Useful for command-line arguments. # rw.dash.readFileSync(path[, options]) Equivalent to [rw.readFileSync](#readFileSync), except treats a *path* of `-` as `/dev/stdin`. Useful for command-line arguments. # rw.dash.writeFile(path, data[, options], callback) Equivalent to [rw.writeFile](#writeFile), except treats a *path* of `-` as `/dev/stdout`. Useful for command-line arguments. # rw.dash.writeFileSync(path, data[, options]) Equivalent to [rw.writeFileSync](#writeFileSync), except treats a *path* of `-` as `/dev/stdout`. Useful for command-line arguments. rw-1.3.3/index.js000066400000000000000000000004071304044243400136120ustar00rootroot00000000000000exports.dash = require("./lib/rw/dash"); exports.readFile = require("./lib/rw/read-file"); exports.readFileSync = require("./lib/rw/read-file-sync"); exports.writeFile = require("./lib/rw/write-file"); exports.writeFileSync = require("./lib/rw/write-file-sync"); rw-1.3.3/lib/000077500000000000000000000000001304044243400127125ustar00rootroot00000000000000rw-1.3.3/lib/rw/000077500000000000000000000000001304044243400133425ustar00rootroot00000000000000rw-1.3.3/lib/rw/dash.js000066400000000000000000000010111304044243400146100ustar00rootroot00000000000000var slice = Array.prototype.slice; function dashify(method, file) { return function(path) { var argv = arguments; if (path == "-") (argv = slice.call(argv)).splice(0, 1, file); return method.apply(null, argv); }; } exports.readFile = dashify(require("./read-file"), "/dev/stdin"); exports.readFileSync = dashify(require("./read-file-sync"), "/dev/stdin"); exports.writeFile = dashify(require("./write-file"), "/dev/stdout"); exports.writeFileSync = dashify(require("./write-file-sync"), "/dev/stdout"); rw-1.3.3/lib/rw/decode.js000066400000000000000000000011001304044243400151130ustar00rootroot00000000000000module.exports = function(options) { if (options) { if (typeof options === "string") return encoding(options); if (options.encoding !== null) return encoding(options.encoding); } return identity(); }; function identity() { var chunks = []; return { push: function(chunk) { chunks.push(chunk); }, value: function() { return Buffer.concat(chunks); } }; } function encoding(encoding) { var chunks = []; return { push: function(chunk) { chunks.push(chunk); }, value: function() { return Buffer.concat(chunks).toString(encoding); } }; } rw-1.3.3/lib/rw/encode.js000066400000000000000000000003651304044243400151410ustar00rootroot00000000000000module.exports = function(data, options) { return typeof data === "string" ? new Buffer(data, typeof options === "string" ? options : options && options.encoding !== null ? options.encoding : "utf8") : data; }; rw-1.3.3/lib/rw/read-file-sync.js000066400000000000000000000014061304044243400165030ustar00rootroot00000000000000var fs = require("fs"), decode = require("./decode"); module.exports = function(filename, options) { if (fs.statSync(filename).isFile()) { return fs.readFileSync(filename, options); } else { var fd = fs.openSync(filename, options && options.flag || "r"), decoder = decode(options); while (true) { // eslint-disable-line no-constant-condition try { var buffer = new Buffer(bufferSize), bytesRead = fs.readSync(fd, buffer, 0, bufferSize); } catch (e) { if (e.code === "EOF") break; fs.closeSync(fd); throw e; } if (bytesRead === 0) break; decoder.push(buffer.slice(0, bytesRead)); } fs.closeSync(fd); return decoder.value(); } }; var bufferSize = 1 << 16; rw-1.3.3/lib/rw/read-file.js000066400000000000000000000014411304044243400155300ustar00rootroot00000000000000var fs = require("fs"), decode = require("./decode"); module.exports = function(path, options, callback) { if (arguments.length < 3) callback = options, options = null; switch (path) { case "/dev/stdin": return readStream(process.stdin, options, callback); } fs.stat(path, function(error, stat) { if (error) return callback(error); if (stat.isFile()) return fs.readFile(path, options, callback); readStream(fs.createReadStream(path, options ? {flags: options.flag || "r"} : {}), options, callback); // N.B. flag / flags }); }; function readStream(stream, options, callback) { var decoder = decode(options); stream.on("error", callback); stream.on("data", function(d) { decoder.push(d); }); stream.on("end", function() { callback(null, decoder.value()); }); } rw-1.3.3/lib/rw/write-file-sync.js000066400000000000000000000014701304044243400167230ustar00rootroot00000000000000var fs = require("fs"), encode = require("./encode"); module.exports = function(filename, data, options) { var stat; try { stat = fs.statSync(filename); } catch (error) { if (error.code !== "ENOENT") throw error; } if (!stat || stat.isFile()) { fs.writeFileSync(filename, data, options); } else { var fd = fs.openSync(filename, options && options.flag || "w"), bytesWritten = 0, bytesTotal = (data = encode(data, options)).length; while (bytesWritten < bytesTotal) { try { bytesWritten += fs.writeSync(fd, data, bytesWritten, bytesTotal - bytesWritten, null); } catch (error) { if (error.code === "EPIPE") break; // ignore broken pipe, e.g., | head fs.closeSync(fd); throw error; } } fs.closeSync(fd); } }; rw-1.3.3/lib/rw/write-file.js000066400000000000000000000020261304044243400157470ustar00rootroot00000000000000var fs = require("fs"), encode = require("./encode"); module.exports = function(path, data, options, callback) { if (arguments.length < 4) callback = options, options = null; switch (path) { case "/dev/stdout": return writeStream(process.stdout, "write", data, options, callback); case "/dev/stderr": return writeStream(process.stderr, "write", data, options, callback); } fs.stat(path, function(error, stat) { if (error && error.code !== "ENOENT") return callback(error); if (stat && stat.isFile()) return fs.writeFile(path, data, options, callback); writeStream(fs.createWriteStream(path, options ? {flags: options.flag || "w"} : {}), "end", data, options, callback); // N.B. flag / flags }); }; function writeStream(stream, send, data, options, callback) { stream.on("error", function(error) { callback(error.code === "EPIPE" ? null : error); }); // ignore broken pipe, e.g., | head stream[send](encode(data, options), function(error) { callback(error && error.code === "EPIPE" ? null : error); }); } rw-1.3.3/package.json000066400000000000000000000012441304044243400144330ustar00rootroot00000000000000{ "name": "rw", "version": "1.3.3", "description": "Now stdin and stdout are files.", "keywords": [ "fs", "readFile", "writeFile", "stdin", "stdout" ], "homepage": "https://github.com/mbostock/rw", "license": "BSD-3-Clause", "author": { "name": "Mike Bostock", "url": "http://bost.ocks.org/mike" }, "main": "index.js", "repository": { "type": "git", "url": "http://github.com/mbostock/rw.git" }, "scripts": { "test": "test/run-tests && eslint index.js lib", "prepublish": "npm test", "postpublish": "git push && git push --tags" }, "devDependencies": { "d3-queue": "3", "eslint": "3" } } rw-1.3.3/test/000077500000000000000000000000001304044243400131235ustar00rootroot00000000000000rw-1.3.3/test/cat-async000077500000000000000000000003641304044243400147360ustar00rootroot00000000000000#!/usr/bin/env node var rw = require("../").dash; rw.readFile(process.argv[2] || "-", "utf8", function(error, contents) { if (error) throw error; rw.writeFile("-", contents, "utf8", function(error) { if (error) throw error; }); }); rw-1.3.3/test/cat-sync000077500000000000000000000002041304044243400145660ustar00rootroot00000000000000#!/usr/bin/env node var rw = require("../").dash; rw.writeFileSync("-", rw.readFileSync(process.argv[2] || "-", "utf8"), "utf8"); rw-1.3.3/test/encode-object-async000077500000000000000000000002631304044243400166660ustar00rootroot00000000000000#!/usr/bin/env node var rw = require("../").dash; rw.writeFile(process.argv[2] || "-", "gréén\n", {encoding: process.argv[3]}, function(error) { if (error) throw error; }); rw-1.3.3/test/encode-object-sync000077500000000000000000000002101304044243400165150ustar00rootroot00000000000000#!/usr/bin/env node var rw = require("../").dash; rw.writeFileSync(process.argv[2] || "-", "gréén\n", {encoding: process.argv[3]}); rw-1.3.3/test/encode-string-async000077500000000000000000000002471304044243400167300ustar00rootroot00000000000000#!/usr/bin/env node var rw = require("../").dash; rw.writeFile(process.argv[2] || "-", "gréén\n", process.argv[3], function(error) { if (error) throw error; }); rw-1.3.3/test/encode-string-sync000077500000000000000000000001741304044243400165660ustar00rootroot00000000000000#!/usr/bin/env node var rw = require("../").dash; rw.writeFileSync(process.argv[2] || "-", "gréén\n", process.argv[3]); rw-1.3.3/test/encoding-async000077500000000000000000000024421304044243400157540ustar00rootroot00000000000000#!/usr/bin/env node var fs = require("fs"), queue = require("d3-queue").queue, rw = require("../"); var code = 0; queue(1) .defer(testRead, "utf8", "gréén\n") .defer(testRead, {encoding: "utf8"}, "gréén\n") .defer(testRead, "ascii", "grC)C)n\n") .defer(testRead, {encoding: "ascii"}, "grC)C)n\n") .defer(testWrite, "utf8", "gréén\n") .defer(testWrite, {encoding: "utf8"}, "gréén\n") .defer(testWrite, "ascii", "gr��n\n") .defer(testWrite, {encoding: "ascii"}, "gr��n\n") .await(done); function testRead(options, expected, callback) { rw.readFile("test/utf8.txt", options, function(error, actual) { if (error) return void callback(error); if (actual !== expected) console.warn(actual + " !== " + expected), code = 1; callback(null); }); } function testWrite(options, expected, callback) { rw.writeFile("test/encoding-async.out", "gréén\n", options, function(error) { if (error) return void callback(error); fs.readFile("test/encoding-async.out", "utf8", function(error, actual) { if (error) return void callback(error); if (actual !== expected) console.warn(actual + " !== " + expected), code = 1; callback(null); }); }); } function done(error) { if (error) throw error; process.exit(code); } rw-1.3.3/test/encoding-sync000077500000000000000000000030761304044243400156170ustar00rootroot00000000000000#!/usr/bin/env node var fs = require("fs"), rw = require("../"); var code = 0, actual, expected; if ((actual = rw.readFileSync("test/utf8.txt", "utf8")) !== (expected = "gréén\n")) code = 1, console.warn(actual + " !== " + expected); if ((actual = rw.readFileSync("test/utf8.txt", {encoding: "utf8"})) !== (expected = "gréén\n")) code = 1, console.warn(actual + " !== " + expected); if ((actual = rw.readFileSync("test/utf8.txt", "ascii")) !== (expected = "grC)C)n\n")) code = 1, console.warn(actual + " !== " + expected); if ((actual = rw.readFileSync("test/utf8.txt", {encoding: "ascii"})) !== (expected = "grC)C)n\n")) code = 1, console.warn(actual + " !== " + expected); rw.writeFileSync("test/encoding-sync.out", "gréén\n", "utf8"); if ((actual = fs.readFileSync("test/encoding-sync.out", "utf8")) !== (expected = "gréén\n")) code = 1, console.warn(actual + " !== " + expected); rw.writeFileSync("test/encoding-sync.out", "gréén\n", {encoding: "utf8"}); if ((actual = fs.readFileSync("test/encoding-sync.out", "utf8")) !== (expected = "gréén\n")) code = 1, console.warn(actual + " !== " + expected); rw.writeFileSync("test/encoding-sync.out", "gréén\n", "ascii"); if ((actual = fs.readFileSync("test/encoding-sync.out", "utf8")) !== (expected = "gr��n\n")) code = 1, console.warn(actual + " !== " + expected); rw.writeFileSync("test/encoding-sync.out", "gréén\n", {encoding: "ascii"}); if ((actual = fs.readFileSync("test/encoding-sync.out", "utf8")) !== (expected = "gr��n\n")) code = 1, console.warn(actual + " !== " + expected); process.exit(code); rw-1.3.3/test/run-tests000077500000000000000000000114431304044243400150200ustar00rootroot00000000000000#!/bin/bash FILE=test/input.txt rm -f -- $FILE for i in {1..10000}; do printf '%09X\n' $RANDOM >> $FILE; done function test() { if [[ $1 -eq 0 ]] then echo -e "\x1B[1;32m✓ $2\x1B[0m" else echo -e "\x1B[1;31m✗ $2\x1B[0m" fi } test/encoding-sync; test $? "encoding-sync applies the specified encodings" test/encoding-async; test $? "encoding-async applies the specified encodings" [ "$(test/wc-async $FILE)" = "100000" ]; test $? "wc-async reads an entire file" [ "$(test/wc-sync $FILE)" = "100000" ]; test $? "wc-sync reads an entire file" [ "$(test/wc-async < $FILE)" = "100000" ]; test $? "wc-async reads an entire file from stdin" [ "$(test/wc-sync < $FILE)" = "100000" ]; test $? "wc-sync reads an entire file from stdin" [ "$(cat $FILE | test/wc-async)" = "100000" ]; test $? "wc-async reads an entire file from a pipe" [ "$(cat $FILE | test/wc-sync)" = "100000" ]; test $? "wc-sync reads an entire file from a pipe" [ "$(test/cat-async $FILE | wc -c | tr -d ' ')" = "100000" ]; test $? "cat-async reads an entire file and writes it to a pipe" [ "$(test/cat-sync $FILE | wc -c | tr -d ' ')" = "100000" ]; test $? "cat-sync reads an entire file and writes it to a pipe" [ "$(test/cat-async $FILE | test/wc-async)" = "100000" ]; test $? "cat-async reads an entire file and writes it to a pipe to wc-async " [ "$(test/cat-async $FILE | test/wc-sync)" = "100000" ]; test $? "cat-async reads an entire file and writes it to a pipe to wc-sync " [ "$(test/cat-sync $FILE | test/wc-async)" = "100000" ]; test $? "cat-sync reads an entire file and writes it to a pipe to wc-async " [ "$(test/cat-sync $FILE | test/wc-sync)" = "100000" ]; test $? "cat-sync reads an entire file and writes it to a pipe to wc-sync " [ "$(test/cat-async < $FILE | wc -c | tr -d ' ')" = "100000" ]; test $? "cat-async reads an entire file from stdin and writes it to a pipe" [ "$(test/cat-sync < $FILE | wc -c | tr -d ' ')" = "100000" ]; test $? "cat-sync reads an entire file from stdin and writes it to a pipe" [ "$(test/cat-async < $FILE | test/wc-async)" = "100000" ]; test $? "cat-async reads an entire file from stdin and writes it to a pipe to wc-async" [ "$(test/cat-async < $FILE | test/wc-sync)" = "100000" ]; test $? "cat-async reads an entire file from stdin and writes it to a pipe to wc-sync" [ "$(test/cat-sync < $FILE | test/wc-async)" = "100000" ]; test $? "cat-sync reads an entire file from stdin and writes it to a pipe to wc-async" [ "$(test/cat-sync < $FILE | test/wc-sync)" = "100000" ]; test $? "cat-sync reads an entire file from stdin and writes it to a pipe to wc-sync" [ "$(cat $FILE | test/cat-async | test/wc-async)" = "100000" ]; test $? "cat-async reads an entire file from a pipe and writes it to a pipe to wc-async" [ "$(cat $FILE | test/cat-async | test/wc-sync)" = "100000" ]; test $? "cat-async reads an entire file from a pipe and writes it to a pipe to wc-sync" [ "$(cat $FILE | test/cat-sync | test/wc-async)" = "100000" ]; test $? "cat-sync reads an entire file from a pipe and writes it to a pipe to wc-async" [ "$(cat $FILE | test/cat-sync | test/wc-sync)" = "100000" ]; test $? "cat-sync reads an entire file from a pipe and writes it to a pipe to wc-sync" [ "$(cat $FILE | test/cat-async | head -n 100 | test/wc-async)" = "1000" ]; test $? "cat-async reads an entire file from a pipe and writes it to a pipe to head to wc-async" [ "$(cat $FILE | test/cat-async | head -n 100 | test/wc-sync)" = "1000" ]; test $? "cat-async reads an entire file from a pipe and writes it to a pipe to head to wc-sync" [ "$(cat $FILE | test/cat-sync | head -n 100 | test/wc-async)" = "1000" ]; test $? "cat-sync reads an entire file from a pipe and writes it to a pipe to head to wc-async" [ "$(cat $FILE | test/cat-sync | head -n 100 | test/wc-sync)" = "1000" ]; test $? "cat-sync reads an entire file from a pipe and writes it to a pipe to head to wc-sync" [ "$(cat $FILE 2> /dev/null | head -n 100 | test/cat-async | test/wc-async)" = "1000" ]; test $? "cat-async reads the head of a file from a pipe and writes it to wc-async" [ "$(cat $FILE 2> /dev/null | head -n 100 | test/cat-async | test/wc-sync)" = "1000" ]; test $? "cat-async reads the head of a file from a pipe and writes it to wc-sync" [ "$(cat $FILE 2> /dev/null | head -n 100 | test/cat-sync | test/wc-async)" = "1000" ]; test $? "cat-sync reads the head of a file from a pipe and writes it to wc-async" [ "$(cat $FILE 2> /dev/null | head -n 100 | test/cat-sync | test/wc-sync)" = "1000" ]; test $? "cat-sync reads the head of a file from a pipe and writes it to wc-sync" [ "$(test/write-async test/write.out && cat test/write.out)" = "Hello, world!" ]; test $? "write-async writes an entire file" [ "$(test/write-sync test/write.out && cat test/write.out)" = "Hello, world!" ]; test $? "write-sync writes an entire file" rm -f -- $FILE test/write.out test/encoding-sync.out test/encoding-async.out rw-1.3.3/test/utf8.txt000066400000000000000000000000101304044243400145410ustar00rootroot00000000000000gréén rw-1.3.3/test/wc-async000077500000000000000000000002621304044243400145750ustar00rootroot00000000000000#!/usr/bin/env node var rw = require("../").dash; rw.readFile(process.argv[2] || "-", function(error, contents) { if (error) throw error; console.log(contents.length); }); rw-1.3.3/test/wc-sync000077500000000000000000000001711304044243400144330ustar00rootroot00000000000000#!/usr/bin/env node var rw = require("../").dash; console.log(rw.readFileSync(process.argv[2] || "-", "utf8").length); rw-1.3.3/test/write-async000077500000000000000000000002421304044243400153140ustar00rootroot00000000000000#!/usr/bin/env node var rw = require("../").dash; rw.writeFile(process.argv[2] || "-", "Hello, world!", "utf8", function(error) { if (error) throw error; }); rw-1.3.3/test/write-sync000077500000000000000000000001671304044243400151610ustar00rootroot00000000000000#!/usr/bin/env node var rw = require("../").dash; rw.writeFileSync(process.argv[2] || "-", "Hello, world!", "utf8");