# is-file-open

> Checks if a file is used by another process on macOS

Latest version **0.1.4** (published 2017-09-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-file-open
pnpm add is-file-open
yarn add is-file-open
bun add is-file-open
```

## 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.1.4 |
| Published | 2017-09-21 |
| First published | 2017-09-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 8 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Adam Bergman |
| Maintainers | adambrgmn |

## Links

- npm: https://www.npmjs.com/package/is-file-open
- Repository: git@github.com:adambrgmn/is-file-open
- Issues: https://github.com/adambrgmn/is-file-open/issues
- npm.io page: https://npm.io/package/is-file-open

## Recent versions

- 0.1.4 (latest) — 2017-09-21
- 0.1.3 — 2017-09-21
- 0.1.2 — 2017-09-21
- 0.1.1 — 2017-09-21
- 0.1.0 — 2017-09-21

## README

# is file open

> Checks if a file is used by another process on macOS using [lsof](https://danielmiessler.com/study/lsof/)

**NOTE** that this module is only tested on macOS 10.12 and that the implementation might not work on Linux (I've bee told that `lsof` requires `sudo`) and most certainly not on Windows either.

## Installation

```sh
# with npm
$ npm install is-file-open

# with yarn
$ yarn add is-file-open
```


## Requirements

This module is using `async/await` and a few ES2015 features therefore Node 8 or above is required.  
This module is only tested on macOS 10.12 and might not work on Linux, and will most likely not work on Windows.


## Usage

```js
const path = require('path');
const isFileOpen = require('is-file-open');

async function run() {
  const filePath = path.resolve(__dirname, 'README.md');
  const fileData = await isFileOpen(filePath);
  console.log(fileData);
}
```

This will output something similar to this:

```js
{
  isOpen: true,
  processes: [
    {
      command: 'Atom\\x20H',
      pid: 774,
      user: 'username',
      fd: '28r',
      type: 'REG',
      device: '1,2',
      'size/off': 70,
      node: 90901449,
      name: '/Users/username/README.md',
    },
    {
      command: 'node',
      pid: 11576,
      user: 'username',
      fd: '12u',
      type: 'REG',
      device: '1,2',
      'size/off': 70,
      node: 90901449,
      name: '/Users/username/README.md',
    },
  ],
};
```

The processes property is a straight translation from from the output of `lsof`.


## API

### isFileOpen(filePath)

| Arg | Type | Required |
|:----|:-----|:---------|
| filePath | `string` | :heavy_check_mark: |

`isFileOpen(filePath)` is an async function that eventually will resolve an object with data concerning the file.

| Prop | Type |
|:-----|:-----|
| isOpen | `boolean` |
| processes | `Array<process>` |

#### type process

`isOpenFile` resolves information about each process currently accessing the file.

| Prop | Type |
|:-----|:-----|
| command | `string` |
| pid | `number` |
| user | `string` |
| fd | `string` |
| type | `string` |
| device | `string` |
| 'size/off' | `number` |
| node | `number` |
| name | `string` |


## License

MIT © [Adam Bergman](https://github.com/adambrgmn)

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