Initial commit
This commit is contained in:
26
node_modules/rw/LICENSE
generated
vendored
Normal file
26
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.
|
||||
5
node_modules/rw/index.js
generated
vendored
Normal file
5
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
node_modules/rw/lib/rw/dash.js
generated
vendored
Normal file
14
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
node_modules/rw/lib/rw/decode.js
generated
vendored
Normal file
23
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
node_modules/rw/lib/rw/encode.js
generated
vendored
Normal file
7
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
node_modules/rw/lib/rw/read-file-sync.js
generated
vendored
Normal file
29
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
node_modules/rw/lib/rw/read-file.js
generated
vendored
Normal file
23
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
node_modules/rw/lib/rw/write-file-sync.js
generated
vendored
Normal file
32
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
node_modules/rw/lib/rw/write-file.js
generated
vendored
Normal file
22
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); });
|
||||
}
|
||||
20
node_modules/rw/package.json
generated
vendored
Normal file
20
node_modules/rw/package.json
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "rw",
|
||||
"version": "1.3.3",
|
||||
"description": "Now stdin and stdout are files.",
|
||||
"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"
|
||||
},
|
||||
"devDependencies": {
|
||||
"d3-queue": "3",
|
||||
"eslint": "3"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user