# resin-image-fs

> Resin.io image filesystem manipulation utilities

Latest version **6.0.0** (published 2020-07-24) · Apache-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install resin-image-fs
pnpm add resin-image-fs
yarn add resin-image-fs
bun add resin-image-fs
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2020-07-24 |
| First published | 2015-07-20 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 39.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Juan Cruz Viotti |
| Maintainers | balena.io |
| Keywords | resin, fs, filesystem, device, image |

## Links

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

## Dependencies (7)

- [fatfs](https://npm.io/package/fatfs.md) ^0.10.6
- [ext2fs](https://npm.io/package/ext2fs.md) ^1.0.28
- [lodash](https://npm.io/package/lodash.md) ^4.17.5
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.1
- [file-disk](https://npm.io/package/file-disk.md) ^7.0.1
- [partitioninfo](https://npm.io/package/partitioninfo.md) ^6.0.0
- [replacestream](https://npm.io/package/replacestream.md) ^4.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

- 6.0.0 (latest) — 2020-07-24
- 6.0.0-update-file-disk-2-2596a1c286adb8ecb78b113ff2b17be09b0f0945 — 2020-07-24
- 5.0.9 — 2020-03-02
- 5.0.9-update-dev-deps-c84f474d1b27709539d4f2db2606e29221d83e40 — 2020-03-02
- 5.0.8 — 2019-05-06
- 5.0.8-node12-41aa655ef43b10863877ec3fb2e0c40f0810df9a — 2019-05-06
- 5.0.7 — 2019-04-05
- 5.0.7-update-file-disk-6-679af85a3ee01916413fc931899f6e83703ff0fa — 2019-04-04
- 5.0.6 — 2019-01-14
- 5.0.6-update-partitioninfo-95d7c631d1341164839649af6459a78afff72d12 — 2019-01-14
- 5.0.5 — 2018-11-29
- 5.0.5-update-file-disk-8c10bb2cd91ca967531d693450e87c1684dfaeef — 2018-11-29
- 5.0.4 — 2018-05-01
- 5.0.3 — 2018-04-30
- 5.0.2 — 2018-04-25
- … 17 more at https://npm.io/package/resin-image-fs/versions

## README

resin-image-fs
--------------

[![npm version](https://badge.fury.io/js/resin-image-fs.svg)](http://badge.fury.io/js/resin-image-fs)
[![dependencies](https://david-dm.org/resin-io/resin-image-fs.png)](https://david-dm.org/resin-io/resin-image-fs.png)
[![Build Status](https://travis-ci.org/resin-io/resin-image-fs.svg?branch=master)](https://travis-ci.org/resin-io/resin-image-fs)
[![Build status](https://ci.appveyor.com/api/projects/status/86bot1jaepcg5xlv?svg=true)](https://ci.appveyor.com/project/resin-io/resin-image-fs)

Join our online chat at [![Gitter chat](https://badges.gitter.im/resin-io/chat.png)](https://gitter.im/resin-io/chat)

Resin.io image filesystem manipulation utilities.

Role
----

The intention of this module is to provide low level utilities to Resin.io operating system data partitions.

**THIS MODULE IS LOW LEVEL AND IS NOT MEANT TO BE USED BY END USERS DIRECTLY**.

Installation
------------

Install `resin-image-fs` by running:

```sh
$ npm install --save resin-image-fs
```

Documentation
-------------


* [imagefs](#module_imagefs)
    * [.interact(disk, partition)](#module_imagefs.interact) ⇒ <code>bluebird.disposer.&lt;fs&gt;</code>
    * [.read(definition)](#module_imagefs.read) ⇒ <code>bluebird.disposer.&lt;ReadStream&gt;</code>
    * [.write(definition, stream)](#module_imagefs.write) ⇒ <code>Promise</code>
    * [.readFile(definition)](#module_imagefs.readFile) ⇒ <code>Promise.&lt;String&gt;</code>
    * [.writeFile(definition, contents)](#module_imagefs.writeFile) ⇒ <code>Promise</code>
    * [.copy(input, output)](#module_imagefs.copy) ⇒ <code>Promise</code>
    * [.replace(definition, search, replace)](#module_imagefs.replace) ⇒ <code>Promise</code>
    * [.listDirectory(definition)](#module_imagefs.listDirectory) ⇒ <code>Promise.&lt;Array.&lt;String&gt;&gt;</code>

<a name="module_imagefs.interact"></a>

### imagefs.interact(disk, partition) ⇒ <code>bluebird.disposer.&lt;fs&gt;</code>
**Kind**: static method of [<code>imagefs</code>](#module_imagefs)  
**Summary**: Get a bluebird.disposer of a node fs like interface for a partition  
**Returns**: <code>bluebird.disposer.&lt;fs&gt;</code> - node fs like interface  
**Access**: public  

| Param | Type | Description |
| --- | --- | --- |
| disk | <code>String</code> \| <code>filedisk.Disk</code> | path to the image or filedisk.Disk instance |
| partition | <code>Number</code> | partition number |

**Example**  
```js
Promise.using imagefs.interact('/foo/bar.img', 5), (fs) ->
  fs.readFileAsync('/bar/qux')
  .then (contents) ->
    console.log(contents)
```
<a name="module_imagefs.read"></a>

### imagefs.read(definition) ⇒ <code>bluebird.disposer.&lt;ReadStream&gt;</code>
**Kind**: static method of [<code>imagefs</code>](#module_imagefs)  
**Summary**: Get a device file readable stream  
**Returns**: <code>bluebird.disposer.&lt;ReadStream&gt;</code> - file stream  
**Access**: public  

| Param | Type | Description |
| --- | --- | --- |
| definition | <code>Object</code> | device path definition |
| definition.image | <code>String</code> \| <code>filedisk.Disk</code> | path to the image or filedisk.Disk instance |
| [definition.partition] | <code>Number</code> | partition number |
| definition.path | <code>String</code> | file path |

**Example**  
```js
disposer = imagefs.read
	image: '/foo/bar.img'
	partition: 5
	path: '/baz/qux'

Promise.using disposer, (stream) ->
  out = fs.createWriteStream('/bar/qux')
  stream.pipe(out)
  utils.waitStream(out)
```
<a name="module_imagefs.write"></a>

### imagefs.write(definition, stream) ⇒ <code>Promise</code>
**Kind**: static method of [<code>imagefs</code>](#module_imagefs)  
**Summary**: Write a stream to a device file  
**Access**: public  

| Param | Type | Description |
| --- | --- | --- |
| definition | <code>Object</code> | device path definition |
| definition.image | <code>String</code> \| <code>filedisk.Disk</code> | path to the image or filedisk.Disk instance |
| [definition.partition] | <code>Number</code> | partition number |
| definition.path | <code>String</code> | file path |
| stream | <code>ReadStream</code> | contents stream |

**Example**  
```js
imagefs.write
	image: '/foo/bar.img'
	partition: 2
	path: '/baz/qux'
, fs.createReadStream('/baz/qux')
```
<a name="module_imagefs.readFile"></a>

### imagefs.readFile(definition) ⇒ <code>Promise.&lt;String&gt;</code>
**Kind**: static method of [<code>imagefs</code>](#module_imagefs)  
**Summary**: Read a device file  
**Returns**: <code>Promise.&lt;String&gt;</code> - file text  
**Access**: public  

| Param | Type | Description |
| --- | --- | --- |
| definition | <code>Object</code> | device path definition |
| definition.image | <code>String</code> \| <code>filedisk.Disk</code> | path to the image or filedisk.Disk instance |
| [definition.partition] | <code>Number</code> | partition number |
| definition.path | <code>String</code> | file path |

**Example**  
```js
imagefs.readFile
	image: '/foo/bar.img'
	partition: 5
	path: '/baz/qux'
.then (contents) ->
	console.log(contents)
```
<a name="module_imagefs.writeFile"></a>

### imagefs.writeFile(definition, contents) ⇒ <code>Promise</code>
**Kind**: static method of [<code>imagefs</code>](#module_imagefs)  
**Summary**: Write a device file  
**Access**: public  

| Param | Type | Description |
| --- | --- | --- |
| definition | <code>Object</code> | device path definition |
| definition.image | <code>String</code> \| <code>filedisk.Disk</code> | path to the image or filedisk.Disk instance |
| [definition.partition] | <code>Number</code> | partition number |
| definition.path | <code>String</code> | file path |
| contents | <code>String</code> | contents string |

**Example**  
```js
imagefs.writeFile
	image: '/foo/bar.img'
	partition: 2
	path: '/baz/qux'
, 'foo bar baz'
```
<a name="module_imagefs.copy"></a>

### imagefs.copy(input, output) ⇒ <code>Promise</code>
**Kind**: static method of [<code>imagefs</code>](#module_imagefs)  
**Summary**: Copy a device file  
**Access**: public  

| Param | Type | Description |
| --- | --- | --- |
| input | <code>Object</code> | input device path definition |
| definition.image | <code>String</code> \| <code>filedisk.Disk</code> | path to the image or filedisk.Disk instance |
| [input.partition] | <code>Number</code> | partition number |
| input.path | <code>String</code> | file path |
| output | <code>Object</code> | output device path definition |
| output.image | <code>String</code> | path to the image |
| [output.partition] | <code>Number</code> | partition number |
| output.path | <code>String</code> | file path |

**Example**  
```js
imagefs.copy
	image: '/foo/bar.img'
	partition: 2
	path: '/baz/qux'
,
	image: '/foo/bar.img'
	partition: 5
	path: '/baz/hello'
```
<a name="module_imagefs.replace"></a>

### imagefs.replace(definition, search, replace) ⇒ <code>Promise</code>
**Kind**: static method of [<code>imagefs</code>](#module_imagefs)  
**Summary**: Perform search and replacement in a file  
**Access**: public  

| Param | Type | Description |
| --- | --- | --- |
| definition | <code>Object</code> | device path definition |
| definition.image | <code>String</code> \| <code>filedisk.Disk</code> | path to the image or filedisk.Disk instance |
| [definition.partition] | <code>Number</code> | partition number |
| definition.path | <code>String</code> | file path |
| search | <code>String</code> \| <code>RegExp</code> | search term |
| replace | <code>String</code> | replace value |

**Example**  
```js
imagefs.replace
	image: '/foo/bar.img'
	partition: 2
	path: '/baz/qux'
, 'bar', 'baz'
```
<a name="module_imagefs.listDirectory"></a>

### imagefs.listDirectory(definition) ⇒ <code>Promise.&lt;Array.&lt;String&gt;&gt;</code>
**Kind**: static method of [<code>imagefs</code>](#module_imagefs)  
**Summary**: List the contents of a directory  
**Returns**: <code>Promise.&lt;Array.&lt;String&gt;&gt;</code> - list of files in directory  
**Access**: public  

| Param | Type | Description |
| --- | --- | --- |
| definition | <code>Object</code> | device path definition |
| definition.image | <code>String</code> \| <code>filedisk.Disk</code> | path to the image or filedisk.Disk instance |
| [definition.partition] | <code>Number</code> | partition number |
| definition.path | <code>String</code> | directory path |

**Example**  
```js
imagefs.listDirectory
	image: '/foo/bar.img'
	partition: 5
	path: '/my/directory'
.then (files) ->
	console.log(files)
```

Support
-------

If you're having any problem, please [raise an issue](https://github.com/resin-io/resin-image-fs/issues/new) on GitHub and the Resin.io team will be happy to help.

Tests
-----

Run the test suite by doing:

```sh
$ npm test
```

Contribute
----------

- Issue Tracker: [github.com/resin-io/resin-image-fs/issues](https://github.com/resin-io/resin-image-fs/issues)
- Source Code: [github.com/resin-io/resin-image-fs](https://github.com/resin-io/resin-image-fs)

Before submitting a PR, please make sure that you include tests, and that [coffeelint](http://www.coffeelint.org/) runs without any warning:

```sh
$ npm test
```

License
-------

The project is licensed under the Apache 2.0 license.

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