How to use the createReadStream function from graceful-fs
Find comprehensive JavaScript graceful-fs.createReadStream code examples handpicked from public code repositorys.
graceful-fs.createReadStream is a method used to create a readable stream to read data from a file.
GitHub: canarddu38/DUCKSPLOIT
442 443 444 445 446 447 448 449 450 451 452 453
// copy exports.copyDir = copyDir; exports.copyFile = copyFile; // createStream exports.createReadStream = fs.createReadStream; exports.createWriteStream = fs.createWriteStream; // emptyDir exports.emptyDir = emptyDir;
+ 7 other calls in file
GitHub: mmraff/untar-to-memory
113 114 115 116 117 118 119 120 121 122 123
function checkHeader(tarball, params, next, cb0) { const debug = params.log let error let nextResult const rstr = fs.createReadStream(tarball) const setResult = (err, data) => { if (err) { // Ensure that any previous error is preserved /* istanbul ignore else - difficult to create multiple error case */
+ 24 other calls in file
How does graceful-fs.createReadStream work?
graceful-fs.createReadStream is a method in the graceful-fs library that creates a readable stream to read data from a file in a non-blocking way, with graceful error handling and retrying when faced with errors. When a file is opened with this method, the method returns a ReadableStream instance that emits data events as data is read from the file. It takes the file path as the first argument and options for reading the file as the second argument, such as the encoding to use, highWaterMark, and start and end positions. The method internally uses fs.createReadStream, with some additional logic for handling errors and retries.
GitHub: csyslabs/csyslabs.github.io
13 14 15 16 17 18 19 20 21 22
const mkdirAsync = Promise.promisify(fs.mkdir); const writeFileAsync = Promise.promisify(fs.writeFile); const appendFileAsync = Promise.promisify(fs.appendFile); const rmdirAsync = Promise.promisify(fs.rmdir); const readFileAsync = Promise.promisify(fs.readFile); const createReadStream = fs.createReadStream; const createWriteStream = fs.createWriteStream; const accessSync = fs.accessSync; const accessAsync = Promise.promisify(fs.access);
+ 7 other calls in file
GitHub: lesly-mlab/mlab-app-v2
92 93 94 95 96 97 98 99 100 101
} }) } function copyFile (file, target) { var readStream = fs.createReadStream(file.name) var writeStream = fs.createWriteStream(target, { mode: file.mode }) readStream.on('error', onError) writeStream.on('error', onError)
Ai Example
1 2 3 4 5
const fs = require("graceful-fs"); const readStream = fs.createReadStream("file.txt"); const writeStream = fs.createWriteStream("copy.txt"); readStream.pipe(writeStream);
In this example, the createReadStream method is used to create a readable stream from a file named 'file.txt'. The resulting stream is then piped to a writable stream created by createWriteStream, which writes the contents of the readable stream to a new file named 'copy.txt'.
280 281 282 283 284 285 286 287 288 289 290
function untarStream (tarball, cb) { validate('SF', arguments) cb = once(cb) var stream var file = stream = fs.createReadStream(tarball) var tounpipe = [file] file.on('error', function (er) { er = new Error('Error extracting ' + tarball + ' archive: ' + er.message) er.code = 'EREADFILE'
+ 14 other calls in file
109 110 111 112 113 114 115 116 117
fs.createReadStream(writeStream.__atomicTmp) .on('data', function (data, enc) { tmpFileHash.update(data, enc) }) .on('error', fileHashError) .on('end', fileHashComplete) fs.createReadStream(writeStream.__atomicTarget) .on('data', function (data, enc) { targetFileHash.update(data, enc) }) .on('error', fileHashError) .on('end', fileHashComplete)
+ 3 other calls in file
GitHub: Sathish9686/Gadgets-Page
7 8 9 10 11 12 13 14 15 16 17 18 19
exports.closeSync = fs.closeSync.bind(fs); exports.createWriteStream = fs.createWriteStream.bind(fs); exports.createReadStream = (path, options) => new Promise((resolve, reject) => { const read = fs.createReadStream(path, options); read.once('error', error => { reject(new CpFileError(`Cannot read from \`${path}\`: ${error.message}`, error)); });
graceful-fs.promises is the most popular function in graceful-fs (1135 examples)