add lisp packages
This commit is contained in:
5
lisp/emacs-application-framework/app/mermaid/node_modules/rw/.eslintrc
generated
vendored
Normal file
5
lisp/emacs-application-framework/app/mermaid/node_modules/rw/.eslintrc
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
env:
|
||||
node: true
|
||||
|
||||
extends:
|
||||
"eslint:recommended"
|
||||
3
lisp/emacs-application-framework/app/mermaid/node_modules/rw/.npmignore
generated
vendored
Normal file
3
lisp/emacs-application-framework/app/mermaid/node_modules/rw/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
test/input.txt
|
||||
26
lisp/emacs-application-framework/app/mermaid/node_modules/rw/LICENSE
generated
vendored
Normal file
26
lisp/emacs-application-framework/app/mermaid/node_modules/rw/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
Copyright (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.
|
||||
120
lisp/emacs-application-framework/app/mermaid/node_modules/rw/README.md
generated
vendored
Normal file
120
lisp/emacs-application-framework/app/mermaid/node_modules/rw/README.md
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
# 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
|
||||
|
||||
<a name="readFile" href="#readFile">#</a> rw.<b>readFile</b>(<i>path</i>[, <i>options</i>], <i>callback</i>)
|
||||
|
||||
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.
|
||||
|
||||
<a name="readFileSync" href="#readFileSync">#</a> rw.<b>readFileSync</b>(<i>path</i>[, <i>options</i>])
|
||||
|
||||
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.
|
||||
|
||||
<a name="writeFile" href="#writeFile">#</a> rw.<b>writeFile</b>(<i>path</i>, <i>data</i>[, <i>options</i>], <i>callback</i>)
|
||||
|
||||
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.
|
||||
|
||||
<a name="writeFileSync" href="#writeFileSync">#</a> rw.<b>writeFileSync</b>(<i>path</i>, <i>data</i>[, <i>options</i>])
|
||||
|
||||
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.
|
||||
|
||||
<a name="dash_readFile" href="#dash_readFile">#</a> rw.dash.<b>readFile</b>(<i>path</i>[, <i>options</i>], <i>callback</i>)
|
||||
|
||||
Equivalent to [rw.readFile](#readFile), except treats a *path* of `-` as `/dev/stdin`. Useful for command-line arguments.
|
||||
|
||||
<a name="dash_readFileSync" href="#dash_readFileSync">#</a> rw.dash.<b>readFileSync</b>(<i>path</i>[, <i>options</i>])
|
||||
|
||||
Equivalent to [rw.readFileSync](#readFileSync), except treats a *path* of `-` as `/dev/stdin`. Useful for command-line arguments.
|
||||
|
||||
<a name="dash_writeFile" href="#dash_writeFile">#</a> rw.dash.<b>writeFile</b>(<i>path</i>, <i>data</i>[, <i>options</i>], <i>callback</i>)
|
||||
|
||||
Equivalent to [rw.writeFile](#writeFile), except treats a *path* of `-` as `/dev/stdout`. Useful for command-line arguments.
|
||||
|
||||
<a name="dash_writeFileSync" href="#dash_writeFileSync">#</a> rw.dash.<b>writeFileSync</b>(<i>path</i>, <i>data</i>[, <i>options</i>])
|
||||
|
||||
Equivalent to [rw.writeFileSync](#writeFileSync), except treats a *path* of `-` as `/dev/stdout`. Useful for command-line arguments.
|
||||
5
lisp/emacs-application-framework/app/mermaid/node_modules/rw/index.js
generated
vendored
Normal file
5
lisp/emacs-application-framework/app/mermaid/node_modules/rw/index.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
exports.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");
|
||||
14
lisp/emacs-application-framework/app/mermaid/node_modules/rw/lib/rw/dash.js
generated
vendored
Normal file
14
lisp/emacs-application-framework/app/mermaid/node_modules/rw/lib/rw/dash.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
var 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");
|
||||
23
lisp/emacs-application-framework/app/mermaid/node_modules/rw/lib/rw/decode.js
generated
vendored
Normal file
23
lisp/emacs-application-framework/app/mermaid/node_modules/rw/lib/rw/decode.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
module.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); }
|
||||
};
|
||||
}
|
||||
7
lisp/emacs-application-framework/app/mermaid/node_modules/rw/lib/rw/encode.js
generated
vendored
Normal file
7
lisp/emacs-application-framework/app/mermaid/node_modules/rw/lib/rw/encode.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = function(data, options) {
|
||||
return typeof data === "string"
|
||||
? new Buffer(data, typeof options === "string" ? options
|
||||
: options && options.encoding !== null ? options.encoding
|
||||
: "utf8")
|
||||
: data;
|
||||
};
|
||||
29
lisp/emacs-application-framework/app/mermaid/node_modules/rw/lib/rw/read-file-sync.js
generated
vendored
Normal file
29
lisp/emacs-application-framework/app/mermaid/node_modules/rw/lib/rw/read-file-sync.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
var 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;
|
||||
23
lisp/emacs-application-framework/app/mermaid/node_modules/rw/lib/rw/read-file.js
generated
vendored
Normal file
23
lisp/emacs-application-framework/app/mermaid/node_modules/rw/lib/rw/read-file.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
var 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()); });
|
||||
}
|
||||
32
lisp/emacs-application-framework/app/mermaid/node_modules/rw/lib/rw/write-file-sync.js
generated
vendored
Normal file
32
lisp/emacs-application-framework/app/mermaid/node_modules/rw/lib/rw/write-file-sync.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
var 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);
|
||||
}
|
||||
};
|
||||
22
lisp/emacs-application-framework/app/mermaid/node_modules/rw/lib/rw/write-file.js
generated
vendored
Normal file
22
lisp/emacs-application-framework/app/mermaid/node_modules/rw/lib/rw/write-file.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
var 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); });
|
||||
}
|
||||
32
lisp/emacs-application-framework/app/mermaid/node_modules/rw/package.json
generated
vendored
Normal file
32
lisp/emacs-application-framework/app/mermaid/node_modules/rw/package.json
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
}
|
||||
10
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/cat-async
generated
vendored
Executable file
10
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/cat-async
generated
vendored
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/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;
|
||||
});
|
||||
});
|
||||
5
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/cat-sync
generated
vendored
Executable file
5
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/cat-sync
generated
vendored
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var rw = require("../").dash;
|
||||
|
||||
rw.writeFileSync("-", rw.readFileSync(process.argv[2] || "-", "utf8"), "utf8");
|
||||
7
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/encode-object-async
generated
vendored
Executable file
7
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/encode-object-async
generated
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/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;
|
||||
});
|
||||
5
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/encode-object-sync
generated
vendored
Executable file
5
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/encode-object-sync
generated
vendored
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var rw = require("../").dash;
|
||||
|
||||
rw.writeFileSync(process.argv[2] || "-", "gréén\n", {encoding: process.argv[3]});
|
||||
7
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/encode-string-async
generated
vendored
Executable file
7
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/encode-string-async
generated
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/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;
|
||||
});
|
||||
5
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/encode-string-sync
generated
vendored
Executable file
5
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/encode-string-sync
generated
vendored
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var rw = require("../").dash;
|
||||
|
||||
rw.writeFileSync(process.argv[2] || "-", "gréén\n", process.argv[3]);
|
||||
42
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/encoding-async
generated
vendored
Executable file
42
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/encoding-async
generated
vendored
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/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<67><72>n\n")
|
||||
.defer(testWrite, {encoding: "ascii"}, "gr<67><72>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);
|
||||
}
|
||||
20
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/encoding-sync
generated
vendored
Executable file
20
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/encoding-sync
generated
vendored
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/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<67><72>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<67><72>n\n")) code = 1, console.warn(actual + " !== " + expected);
|
||||
|
||||
process.exit(code);
|
||||
53
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/run-tests
generated
vendored
Executable file
53
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/run-tests
generated
vendored
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/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
|
||||
1
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/utf8.txt
generated
vendored
Normal file
1
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/utf8.txt
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
gréén
|
||||
8
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/wc-async
generated
vendored
Executable file
8
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/wc-async
generated
vendored
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var rw = require("../").dash;
|
||||
|
||||
rw.readFile(process.argv[2] || "-", function(error, contents) {
|
||||
if (error) throw error;
|
||||
console.log(contents.length);
|
||||
});
|
||||
5
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/wc-sync
generated
vendored
Executable file
5
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/wc-sync
generated
vendored
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var rw = require("../").dash;
|
||||
|
||||
console.log(rw.readFileSync(process.argv[2] || "-", "utf8").length);
|
||||
7
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/write-async
generated
vendored
Executable file
7
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/write-async
generated
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var rw = require("../").dash;
|
||||
|
||||
rw.writeFile(process.argv[2] || "-", "Hello, world!", "utf8", function(error) {
|
||||
if (error) throw error;
|
||||
});
|
||||
5
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/write-sync
generated
vendored
Executable file
5
lisp/emacs-application-framework/app/mermaid/node_modules/rw/test/write-sync
generated
vendored
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var rw = require("../").dash;
|
||||
|
||||
rw.writeFileSync(process.argv[2] || "-", "Hello, world!", "utf8");
|
||||
Reference in New Issue
Block a user