Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rw

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rw - npm Package Compare versions

Comparing version 1.3.2 to 1.3.3

.eslintrc

2

lib/rw/read-file-sync.js

@@ -11,3 +11,3 @@ var fs = require("fs"),

while (true) {
while (true) { // eslint-disable-line no-constant-condition
try {

@@ -14,0 +14,0 @@ var buffer = new Buffer(bufferSize),

var fs = require("fs"),
decode = require("./decode");
module.exports = function(filename, options, callback) {
module.exports = function(path, options, callback) {
if (arguments.length < 3) callback = options, options = null;
fs.stat(filename, function(error, stat) {
if (error) return callback(error);
if (stat.isFile()) {
fs.readFile(filename, options, callback);
} else {
var decoder = decode(options), stream;
switch (filename) {
case "/dev/stdin": stream = process.stdin; break;
default: stream = fs.createReadStream(filename, options ? {flags: options.flag || "r"} : {}); break; // N.B. flag / flags
}
switch (path) {
case "/dev/stdin": return readStream(process.stdin, options, callback);
}
stream
.on("error", callback)
.on("data", function(d) { decoder.push(d); })
.on("end", function() { callback(null, decoder.value()); });
}
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()); });
}
var fs = require("fs"),
encode = require("./encode");
module.exports = function(filename, data, options, callback) {
module.exports = function(path, data, options, callback) {
if (arguments.length < 4) callback = options, options = null;
fs.stat(filename, function(error, stat) {
if (error && error.code !== "ENOENT") return callback(error);
if (stat && stat.isFile()) {
fs.writeFile(filename, data, options, callback);
} else {
var stream, send = "end";
switch (filename) {
case "/dev/stdout": stream = process.stdout, send = "write"; break;
case "/dev/stderr": stream = process.stderr, send = "write"; break;
default: stream = fs.createWriteStream(filename, options ? {flags: options.flag || "w"} : {}); break; // N.B. flag / flags
}
switch (path) {
case "/dev/stdout": return writeStream(process.stdout, "write", data, options, callback);
case "/dev/stderr": return writeStream(process.stderr, "write", data, options, callback);
}
stream
.on("error", function(error) { callback(error.code === "EPIPE" ? null : error); }) // ignore broken pipe, e.g., | head
[send](encode(data, options), function(error) { callback(error && error.code === "EPIPE" ? null : error); });
}
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); });
}
{
"name": "rw",
"version": "1.3.2",
"version": "1.3.3",
"description": "Now stdin and stdout are files.",

@@ -29,4 +29,5 @@ "keywords": [

"devDependencies": {
"d3-queue": "2"
"d3-queue": "3",
"eslint": "3"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc