# simple-fs

> A node.js implementation of the simple-stream and continuable based fs interface for js-git.

Latest version **0.0.3** (published 2013-07-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install simple-fs
pnpm add simple-fs
yarn add simple-fs
bun add simple-fs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2013-07-20 |
| First published | 2013-07-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Tim Caswell |
| Maintainers | creationix |
| Keywords | simple-stream, continuable, js-git, fs, interface |

## Links

- npm: https://www.npmjs.com/package/simple-fs
- Repository: https://github.com/creationix/simple-fs
- Issues: https://github.com/creationix/simple-fs/issues
- npm.io page: https://npm.io/package/simple-fs

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 0.0.3 (latest) — 2013-07-20
- 0.0.2 — 2013-07-11
- 0.0.1 — 2013-07-11

## README

simple-fs
======

A node.js implementation of the simple-stream and continuable based fs interface for js-git.

## File System Interface

This module implements the following functions from the fs interface which is described in detail at <https://github.com/creationix/js-git/blob/master/specs/fs.md>

- stat(path) -> continuable<stat>
- read(path, [encoding]) -> continuable<value>
- write(path, value, [encoding]) -> continuable
- readStream(path, [options]) -> continuable<stream>
- writeStream(path, [options]) -> continuable<sink>
- unlink(path) -> continuable
- readlink(path) -> continuable<target>
- symlink(path, target) -> continuable
- readdir(path) -> continuable<stream>
- rmdir(path) -> continuable
- mkdir(path) -> continuable
- rename(path, target) -> continuable

```js
var fs = require('simple-fs');

// Streaming copy a file callback style
function copy(source, dest, callback) {
  var stream;
  // Set up a readStream.
  fs.readStream("input.txt", onReadStream);

  function onReadStream(err, result) {
    if (err) return callback(err);
    stream = result;
    // Set up a writable sink
    fs.writeStream("copy.txt", onWriteStream);
  }

  function onWriteStream(err, sink) {
    if (err) return callback(err);
    // Stream from source to sink
    sink(stream, callback);
  }
}

copy("input.txt", "copy.txt", function (err) {
  if (err) throw err;
  console.log("Done Streaming");
});
```

You don't have to store all the steps into variables, so you can simply chain the calls.

Also if you're in an ES6 generator using [gen-run](https://github.com/creationix/gen-run), then consuming the continuable is even easier.

```js
var run = require('gen-run');
var fs = require('simple-fs');

function* copy(source, dest) {
  // Set up a readStream.
  var stream = yield fs.readStream(source);
  // Set up a writable sink
  var sink = yield fs.writeStream(dest);
  // Stream from source to sink
  yield sink(stream);
}

run(function* () {
  yield* copy("input.txt", "copy.txt");
  console.log("Done Streaming");
});
```


### chroot(root) -> fs

In addition to the exports object implementing the fs interface with respect to the filesystem root, you can also create a fs instance that is chrooted to some directory.

```js
var fs = require('simple-fs')("/home/tim/Code/js-git/.git");

// read the first chunk in the staging area's index.
fs.readStream("/index", function (err, stream) {
  if (err) throw err;
  stream.read(console.log);
});
```

## License

The MIT License (MIT)

Copyright (c) 2013 Tim Caswell

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

---
_Source: https://npm.io/package/simple-fs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
