# custom-file

> It abstracts the File and Folder classes, can be used on any virtual file system, and stream supports.

Latest version **0.5.8** (published 2016-03-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install custom-file
pnpm add custom-file
yarn add custom-file
bun add custom-file
```

## 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.5.8 |
| Published | 2016-03-20 |
| First published | 2015-07-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | riceball |
| Keywords | file, fs, dir, directory, folder, abstract, class, klass |

## Links

- npm: https://www.npmjs.com/package/custom-file
- Repository: https://github.com/snowyu/custom-file.js
- Issues: https://github.com/snowyu/custom-file.js/issues
- npm.io page: https://npm.io/package/custom-file

## Dependencies (7)

- [util-ex](https://npm.io/package/util-ex.md) ^0.3.15
- [bluebird](https://npm.io/package/bluebird.md) ^3.3.4
- [strip-bom](https://npm.io/package/strip-bom.md) ^2.0.0
- [inherits-ex](https://npm.io/package/inherits-ex.md) ^1.1.4
- [abstract-file](https://npm.io/package/abstract-file.md) ^0.5.4
- [read-dir-stream](https://npm.io/package/read-dir-stream.md) ^0.4.0
- [strip-bom-stream](https://npm.io/package/strip-bom-stream.md) ^1.0.0

## 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.5.8 (latest) — 2016-03-20
- 0.5.7 — 2016-03-20
- 0.5.6 — 2015-09-05
- 0.5.5 — 2015-09-01
- 0.5.4 — 2015-08-31
- 0.5.3 — 2015-08-30
- 0.5.2 — 2015-08-30
- 0.5.1 — 2015-08-30
- 0.5.0 — 2015-08-30
- 0.4.3 — 2015-08-18
- 0.4.2 — 2015-08-16
- 0.4.1 — 2015-08-16
- 0.4.0 — 2015-08-15
- 0.3.5 — 2015-07-29
- 0.3.4 — 2015-07-28
- … 6 more at https://npm.io/package/custom-file/versions

## README

## custom-file [![npm](https://img.shields.io/npm/v/custom-file.svg)](https://npmjs.org/package/custom-file)

[![Build Status](https://img.shields.io/travis/snowyu/custom-file.js/master.svg)](http://travis-ci.org/snowyu/custom-file.js)
[![Code Climate](https://codeclimate.com/github/snowyu/custom-file.js/badges/gpa.svg)](https://codeclimate.com/github/snowyu/custom-file.js)
[![Test Coverage](https://codeclimate.com/github/snowyu/custom-file.js/badges/coverage.svg)](https://codeclimate.com/github/snowyu/custom-file.js/coverage)
[![downloads](https://img.shields.io/npm/dm/custom-file.svg)](https://npmjs.org/package/custom-file)
[![license](https://img.shields.io/npm/l/custom-file.svg)](https://npmjs.org/package/custom-file)

the custom-file can be used on any virtual file system with stream supports.


## Usage

you must call `setFileSystem()` the `fs` to CustomFile Before use it:

```coffee
through2    = require 'through2'
Stream      = require('stream').Stream
fs          = require 'graceful-fs' #or require 'fs'
CustomFile  = require 'custom-file'

fs.cwd      = process.cwd    # what's the get current working directory function.
fs.path     = require 'path.js' # what's the path package. (>=abstract-file@0.5.4 supports)
CustomFile.setFileSystem(fs) # and should set your filesystem first.

File = CustomFile.File
Folder = CustomFile.Folder

file = File './readme.md', load:true, read:true
console.log file.contents #<Buffer 23...>
file = File './readme.md', load:true, read:true, buffer:false
console.log file.contents instanceof Stream #true
file.pipe process.stdout, end:false #pipe to stdout(the stdout should be never closed.)

file = Folder './', load:true, read:true
console.log file.contents #[<File "README.md">, <Folder "src">,...]
file = Folder './', load:true, read:true, buffer:false
console.log file.contents instanceof Stream #true
file.pipe through2.obj (aFile, enc, next)->next null, aFile.inspect()+'\n'
.pipe process.stdout, end:false

file = CustomFile './readme.md' # the CustomFile can create the file or folder object base on the file path
file.should.be.instanceof File
file = CustomFile './'          # Or use the AdvanceFile with same object.
file.should.be.instanceof Folder

AdvanceFile = require 'custom-file/lib/advance'
file = AdvanceFile './readme.md'
file.should.be.instanceof AdvanceFile
file = AdvanceFile './'
file.should.be.instanceof AdvanceFile

file.loadSync read:true # here can load manually.
file.load read:true, (err, content)->
  console.log content
```

the following is javascript:

```js
var through2 = require('through2');
var Stream = require('stream').Stream;
var fs = require('graceful-fs');
var CustomFile = require('custom-file');

fs.cwd = process.cwd;
CustomFile.setFileSystem(fs);

var File = CustomFile.File;

var Folder = CustomFile.Folder;

var file = File('./readme.md', {
  load: true,
  read: true
});

console.log(file.contents);

file = File('./readme.md', {
  load: true,
  read: true,
  buffer: false
});

console.log(file.contents instanceof Stream);

file.pipe(process.stdout, {
  end: false
});

file = Folder('./', {
  load: true,
  read: true
});

console.log(file.contents);

file = Folder('./', {
  load: true,
  read: true,
  buffer: false
});

console.log(file.contents instanceof Stream);

file.pipe(through2.obj(function(aFile, enc, next) {
  return next(null, aFile.inspect() + '\n');
})).pipe(process.stdout, {
  end: false
});

file = CustomFile('./readme.md'); // create a file object.
file.should.be.instanceof(File)
file = CustomFile('./'); // create a folder object.
file.should.be.instanceof(Folder)

var AdvanceFile = require('custom-file/lib/advance')
file = AdvanceFile('./readme.md')
file.should.be.instanceof(AdvanceFile)
file = AdvanceFile('./')
file.should.be.instanceof(AdvanceFile)

file.loadSync({read: true});
file.load({read: true}, function(err, content) {
  console.log(content);
});
```

## API


See the [abstract-file](https://github.com/snowyu/abstract-file.js).


## Changes

### v0.5

+ [AbstractFolder] add the filter property to filter the files.

### v0.4

+ abstract-folder class.


## TODOs

+ LRUCache-able supports(not yet)
+ abstract file information class
+ abstract file operation ability
  + abstract save supports: I have no idea about this.
    I need more thinking. how to pass it to stream?
  * rename
  * create
  * append
  * delete

## License

MIT

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