How to use the lstat function from graceful-fs

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

graceful-fs.lstat is a method that retrieves the metadata of a file or directory, including its size, type, and other attributes.

200
201
202
203
204
205
206
207
208
209
    return doneOne()
  })
}

function isWritable (path, done) {
  fs.lstat(path, function (err) {
    if (err) {
      if (err.code === 'ENOENT') return done(true)
      return done(false)
    }
fork icon1
star icon0
watch icon0

14
15
16
17
18
19
20
21
22
23
}

pathExists(dstpath, (err, destinationExists) => {
  if (err) return callback(err)
  if (destinationExists) return callback(null)
  fs.lstat(srcpath, (err) => {
    if (err) {
      err.message = err.message.replace('lstat', 'ensureLink')
      return callback(err)
    }
fork icon0
star icon0
watch icon1

+ 5 other calls in file

How does graceful-fs.lstat work?

graceful-fs.lstat() is a method provided by the graceful-fs library that returns information about a file or directory, including its type (file, directory, etc.), permissions, and timestamps. Unlike the standard Node.js fs module's lstat() method, graceful-fs.lstat() also handles certain errors that can occur when working with files on certain platforms.

76
77
78
79
80
81
82
83
84
85
opts.fileFilter      =  opts.fileFilter      || function() { return true; };
opts.directoryFilter =  opts.directoryFilter || function() { return true; };
opts.depth           =  typeof opts.depth === 'undefined' ? 999999999 : opts.depth;
opts.entryType       =  opts.entryType       || 'files';

var statfn = opts.lstat === true ? fs.lstat.bind(fs) : fs.stat.bind(fs);

if (isUndefined(callback2)) {
  fileProcessed = function() { };
  allProcessed = callback1;
fork icon0
star icon0
watch icon1

+ 2 other calls in file

14
15
16
17
18
19
20
21
22
23
}

pathExists(dstpath, (err, destinationExists) => {
  if (err) return callback(err)
  if (destinationExists) return callback(null)
  fs.lstat(srcpath, (err, stat) => {
    if (err) {
      err.message = err.message.replace('lstat', 'ensureLink')
      return callback(err)
    }
fork icon0
star icon0
watch icon1

+ 2 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const fs = require("graceful-fs");

fs.lstat("/path/to/my/file.txt", (err, stats) => {
  if (err) {
    console.error(err);
    return;
  }

  console.log(stats.isFile()); // true
  console.log(stats.isDirectory()); // false
  console.log(stats.size); // size of the file in bytes
  console.log(stats.mode); // file mode (permissions)
  console.log(stats.uid); // user id of the file owner
  console.log(stats.gid); // group id of the file owner
  console.log(stats.atime); // last accessed timestamp
  console.log(stats.mtime); // last modified timestamp
  console.log(stats.ctime); // creation timestamp
});

In this example, graceful-fs.lstat() is used to retrieve the stats of a file located at /path/to/my/file.txt. The stats object returned by the method is then used to retrieve various pieces of information about the file, such as its size, ownership, and timestamps.

9
10
11
12
13
14
15
16
17
18
  })
}

fs.exists(dstpath, function (destinationExists) {
  if (destinationExists) return callback(null)
  fs.lstat(srcpath, function (err, stat) {
    if (err) {
      err.message = err.message.replace('lstat', 'ensureLink')
      return callback(err)
    }
fork icon0
star icon0
watch icon1

+ 9 other calls in file

176
177
178
179
180
181
182
183
184
185
186
187
  }
}


function reflectLinkStat(path, file, callback) {
  // Set file.stat to the reflect current state on disk
  fs.lstat(path, onLstat);


  function onLstat(lstatErr, stat) {
    if (lstatErr) {
      return callback(lstatErr);
fork icon0
star icon0
watch icon1