3.1.4 ā€¢ Published 3 years ago

@extra-fs/promises v3.1.4

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
3 years ago

Useful additions to inbuilt fs module{promises} . šŸ“¦ Node.js, šŸ“œ Files, šŸ“° Docs.

This package provides async versions of functions (in addition to the existing sync and callback-based functions) in the inbuilt fs module, exposed as *Async() from the fs.promises namespace. They can be used with Promise-based asynchronous programming using the await keyword. In addition, callback-based functions, such as readFile, also behave as async functions when a callback is not provided. The idea behind using *Async() function names is to provide a flat module.

In addition, convenience functions such as readFileText and readJson are included. For performing file/directory existence check async exists, assertExists, and assertNotExists can be used. Cleanup of one-item outer directories can be performed with dehuskdir. This package previously included which(), which is now instead suitably included in extra-child-process package.

Stability: Experimental.

const fs = require('extra-fs');


// 1. Read file text.
async function example1() {
  var text = fs.readFileTextSync('.npmignore');
  var text = await fs.readFileText('.npmignore');
  // ā†’ # Source only
  // ā†’ .gitmodules
  // ā†’ .github/
  // ā†’ .docs/
  // ā†’ ...
}
example1();


// 2. Read JSON file.
async function example2() {
  var json = fs.readJsonSync('package.json');
  var json = await fs.readJson('package.json');
  // ā†’ {
  // ā†’   name: 'extra-fs',
  // ā†’   version: '3.0.27',
  // ā†’   description: 'Useful additions to inbuilt fs module.',
  // ā†’   ...
  // ā†’ }
}
example2();


// 3. Assert that a file exists.
async function example3() {
  if (!(await fs.exists('LICENSE'))) throw 'May I see you license sir?';
  await fs.assertExists('LICENSE');
}
example3();


// 4. Get contents of a directory.
async function example4() {
  var contents = fs.readdirSync('src');
  var contents = await fs.readdir('src');
  // ā†’ [
  // ā†’   'index.ts',
  // ā†’   'promises.ts',
  // ā†’   '_all.ts',
  // ā†’   ...
  // ā†’ ]
}
example4();

Index

PropertyDescription
openOpen a file.
closeClose a file.
readRead data from a file.
writeWrite data to a file.
readvRead an array of buffers from file.
writevWrite an array of buffers to file.
ftruncateShorten (truncate) a file.
futimesChange the file system timestamps of a file.
fstatGet information about a file.
fchmodSet the permissions of a file.
fchownSet the owner of a file.
...
linkCreate a hard link to a file or directory.
symlinkCreate a symbolic link to a file or directory.
readlinkRead the contents of a symbolic link.
realpathGet canonical pathname by resolving ., ..
lutimesChange the file system timestamps of an object.
lstatGet information about a file, without dereferencing symbolic links.
lchownSet the owner of a symbolic link.
...
readFileRead the entire contents of a file.
writeFileWrite data to the file, replace if it already exists.
appendFileAppend data to a file, create if it does not exist.
truncateShorten (truncate) a file.
unlinkRemove a file or symbolic link.
utimesChange the file system timestamps of an object.
statGet file status.
copyFileCopy source file to destination, overwite if exists.
readFileTextRead file text with Unix EOL.
writeFileTextWrite file text with system EOL.
readJsonRead JSON file as value.
writeJsonWrite object to JSON file.
watchFileWatch for changes on filename.
unwatchFileStop watching for changes on filename.
watchWatch for changes on filename, where filename is either a file or a directory.
createReadStreamCreate a readable stream with 64kb highWaterMark.
createWriteStreamCreate a writeable stream from a desired start position.
...
mkdirCreate a directory.
mkdtempCreate a unique temporary directory.
opendirOpen a directory.
readdirOpen a directory.
rmdirRemove a directory.
dehuskdirRemove outer one-item directories.
...
accessTest a user's permissions for the file or directory.
chmodChange the permissions of a file.
chownChange owner and group of a file.
renameRename/move a file or directory.
cpCopy source directory to destination, overwite if exists.
rmRemove a file or directory.
existsCheck if file or directory exists.
assertExistsAssert that a file or directory exists.
assertNotExistsAssert that a file or directory does not exist.

References

npm.io

3.0.45

3 years ago

3.0.46

3 years ago

3.0.43

3 years ago

3.0.44

3 years ago

3.0.49

3 years ago

3.0.47

3 years ago

3.0.48

3 years ago

3.0.41

3 years ago

3.0.42

3 years ago

3.0.40

3 years ago

3.0.56

3 years ago

3.0.57

3 years ago

3.0.54

3 years ago

3.0.55

3 years ago

3.0.58

3 years ago

3.0.59

3 years ago

3.0.92

3 years ago

3.0.91

3 years ago

3.0.52

3 years ago

3.0.53

3 years ago

3.0.50

3 years ago

3.0.51

3 years ago

3.0.67

3 years ago

3.0.68

3 years ago

3.0.65

3 years ago

3.0.66

3 years ago

3.0.69

3 years ago

3.0.60

3 years ago

3.0.63

3 years ago

3.0.64

3 years ago

3.0.61

3 years ago

3.0.62

3 years ago

3.1.3

3 years ago

3.0.34

3 years ago

3.1.2

3 years ago

3.0.35

3 years ago

3.1.1

3 years ago

3.0.32

3 years ago

3.1.0

3 years ago

3.0.33

3 years ago

3.0.38

3 years ago

3.0.39

3 years ago

3.0.36

3 years ago

3.1.4

3 years ago

3.0.37

3 years ago

3.0.70

3 years ago

3.0.71

3 years ago

3.0.72

3 years ago

3.0.23

3 years ago

3.0.24

3 years ago

3.0.21

3 years ago

3.0.22

3 years ago

3.0.27

3 years ago

3.0.28

3 years ago

3.0.25

3 years ago

3.0.26

3 years ago

3.0.30

3 years ago

3.0.31

3 years ago

3.0.29

3 years ago

3.0.17

3 years ago

3.0.18

3 years ago

3.0.19

3 years ago

3.0.20

3 years ago

3.0.16

3 years ago

3.0.15

3 years ago

3.0.14

3 years ago

3.0.13

3 years ago