How to use the createWriteStream function from graceful-fs

Find comprehensive JavaScript graceful-fs.createWriteStream code examples handpicked from public code repositorys.

graceful-fs.createWriteStream creates a writable stream to a file using the fs module with improved error handling.

391
392
393
394
395
396
397
398
399
400
401
402
403
}


function ensureWriteStream(path, options = {}) {
  if (!path) throw new TypeError('path is required!');


  return checkParent(path).then(() => fs.createWriteStream(path, options));
}


function ensureWriteStreamSync(path, options) {
  if (!path) throw new TypeError('path is required!');
fork icon9
star icon48
watch icon0

+ 23 other calls in file

14
15
16
17
18
19
20
21
22
23
24
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);


function exists(path, callback) {
fork icon0
star icon1
watch icon0

+ 23 other calls in file

How does graceful-fs.createWriteStream work?

graceful-fs.createWriteStream is a method provided by the graceful-fs library in Node.js, which creates a write stream to a specified file, similar to the built-in fs.createWriteStream method, but with added support for handling certain file system errors and inconsistencies in a graceful manner.

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)
fork icon1
star icon0
watch icon0

259
260
261
262
263
264
265
266
267
268
        res.body,
        new ShaSum((_, checksum) => {
          contentShasums[libPath] = checksum
          log.verbose('content checksum', libPath, checksum)
        }),
        fs.createWriteStream(targetLibPath)
      )
    })
  } // downloadNodeLib()
} // go()
fork icon0
star icon0
watch icon1

Ai Example

1
2
3
4
5
6
const fs = require("graceful-fs");

const writeStream = fs.createWriteStream("example.txt");

writeStream.write("Hello, world!");
writeStream.end();

This code creates a write stream to the file example.txt using graceful-fs, writes the string 'Hello, world!' to the stream, and then ends the stream.

101
102
103
104
105
106
107
108
109
110
}).on('integrity', s => {
  integrity = s
}).on('size', s => {
  size = s
})
const outStream = fs.createWriteStream(tmpTarget, {
  flags: 'wx'
})
errCheck()
return pipe(inputStream, hashStream, outStream).then(() => {
fork icon0
star icon0
watch icon0

4
5
6
7
8
9
10
11
12
13
14
15
16
const CpFileError = require('./cp-file-error');


const fsP = pify(fs);


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);

fork icon0
star icon0
watch icon0