# component-file

> File & FileReader wrappers

Latest version **0.1.1** (published 2014-02-11) · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2014-02-11 |
| First published | 2014-02-11 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Maintainers | tootallnate |
| Keywords | file, utility |

## Links

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

## Dependencies (1)

- [component-emitter](https://npm.io/package/component-emitter.md) *

## 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.1.1 (latest) — 2014-02-11

## README

# File

  File component wrapping the native `File` and `FileReader` objects
  with a higher level API.

## Installation

node.js:

```
$ npm install file-component
```

browser:

```
$ component install component/file
```

## Events

### Reader

  - `error` an error occurred
  - `progress` in progress (`e.percent` etc)
  - `end` read is complete

## Example

```js
var file = require('file');
var input = document.querySelector('input');

input.onchange = function(){
  var img = file(input.files[0]);

  if (!img.is('image/*')) {
    alert('Images only!');
    return;
  }

  var reader = img.toDataURL(function(err, str){
    if (err) throw err;
    var img = document.createElement('img');
    img.src = str;
    img.height = 300;
    document.body.appendChild(img);
  });

  reader.on('progress', function(e){
    console.log(e.percent);
  });
};
```

## API
  
### file(file)

  Wraps a `File` object:

```js
var file = require('file');
file(input.files[0]);
```

### File#is(type)

  Returns a boolean if the file's mime type matches `type`:

```js
var file = require('file');
file(input.files[0]);
file.is('image/*');
file.is('image/jpeg');
file.is('*/json');
```

### File#toArrayBuffer(fn)

  Convert to an `ArrayBuffer` and invoke `fn(err, result)`,
  returns a `Reader`.

### File#toText(fn)

  Convert to text and invoke `fn(err, result)`,
  returns a `Reader`.

### File#toDataURL(fn)

  Convert to a data uri string and invoke `fn(err, result)`,
  returns a `Reader`.

## License

  MIT

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