Skip to content

Commit

Permalink
Merge pull request #221 from Cellule/patch-1
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
jprichardson committed Feb 14, 2016
2 parents 7e37a3c + 8fe9d4d commit 84a9c2c
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,35 @@ var fs = require('fs')
var fse = require('fs-extra')
```

Sync vs Async
-------------
Most methods are async by default (they take a callback with an `Error` as first argument).

Sync methods on the other hand will throw if an error occurs.

Example:

```js
var fs = require('fs-extra')

fs.copy('/tmp/myfile', '/tmp/mynewfile', function (err) {
if (err) return console.error(err)
console.log("success!")
});

try {
fs.copySync('/tmp/myfile', '/tmp/mynewfile')
console.log("success!")
} catch (err) {
console.error(err)
}
```


Methods
-------
- [copy](#copy)
- [copySync](#copysync)
- [copySync](#copy)
- [createOutputStream](#createoutputstreamfile-options)
- [emptyDir](#emptydirdir-callback)
- [emptyDirSync](#emptydirdir-callback)
Expand All @@ -80,10 +104,10 @@ Methods
- [mkdirs](#mkdirsdir-callback)
- [mkdirsSync](#mkdirsdir-callback)
- [move](#movesrc-dest-options-callback)
- [outputFile](#outputfilefile-data-callback)
- [outputFileSync](#outputfilefile-data-callback)
- [outputJson](#outputjsonfile-data-callback)
- [outputJsonSync](#outputjsonfile-data-callback)
- [outputFile](#outputfilefile-data-options-callback)
- [outputFileSync](#outputfilefile-data-options-callback)
- [outputJson](#outputjsonfile-data-options-callback)
- [outputJsonSync](#outputjsonfile-data-options-callback)
- [readJson](#readjsonfile-options-callback)
- [readJsonSync](#readjsonfile-options-callback)
- [remove](#removedir-callback)
Expand All @@ -104,9 +128,11 @@ Methods
Copy a file or directory. The directory can have contents. Like `cp -r`.

Options:
clobber (boolean): overwrite existing file or directory
preserveTimestamps (boolean): will set last modification and access times to the ones of the original source files, default is `false`.
filter: Function or RegExp to filter copied files. If function, return true to include, false to exclude. If RegExp, same as function, where `filter` is `filter.test`.
- clobber (boolean): overwrite existing file or directory
- preserveTimestamps (boolean): will set last modification and access times to the ones of the original source files, default is `false`.
- filter: Function or RegExp to filter copied files. If function, return true to include, false to exclude. If RegExp, same as function, where `filter` is `filter.test`.

Sync: `copySync()`

Example:

Expand All @@ -124,27 +150,6 @@ fs.copy('/tmp/mydir', '/tmp/mynewdir', function (err) {
}) // copies directory, even if it has subdirectories or files
```

### copySync()

**copySync(src, dest, [options])**

Synchronously copies a file or directory. The directory can have contents.


Example:

```js
var fs = require('fs-extra')

try {
fs.copySync('/tmp/mydir', '/tmp/mynewdir')
} catch (err) {
console.error('Oh no, there was an error: ' + err.message)
}
```



### createOutputStream(file, [options])

Exactly like `createWriteStream`, but if the directory does not exist, it's created.
Expand Down Expand Up @@ -296,8 +301,8 @@ fs.mkdirsSync('/tmp/another/path')
Moves a file or directory, even across devices.

Options:
clobber (boolean): overwrite existing file or directory
limit (number): number of concurrent moves, see ncp for more information
- clobber (boolean): overwrite existing file or directory
- limit (number): number of concurrent moves, see ncp for more information

Example:

Expand Down

0 comments on commit 84a9c2c

Please sign in to comment.