Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: document intention and caveats of Buffer API #6020

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/api/fs.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ Error: EISDIR, read
<etc.>
```

## Buffer API

`fs` functions support passing and receiving paths as both strings and Buffers.
The latter is intended for filesystems which support non-UTF-8 filenames (except
NTFS, where the conversion to UTF-8 is done automatically) and is normally not
needed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps,

`fs` functions support passing and receiving paths as both strings
and Buffers. The latter is intended to make it easier to work with
filesystems that allow for non-UTF-8 filenames. For most typical
uses, working with paths as Buffers will be unnecessary.

*Note* that on certain file systems (such as NTFS and HFS+) Node.js
will always encode filenames as UTF-8. On such file systems, passing 
non-UTF-8 encoded Buffers to `fs` functions will not work as expected.


**Caution:** the Buffer API is not portable. On NTFS and HFS+, the incoming
Buffers are always encoded in UTF-8, and passing non-UTF-8 encoded Buffers to
`fs` functions won't work as expected.

## Class: fs.FSWatcher

Objects returned from `fs.watch()` are of this type.
Expand Down