# fs-xattr

> Node.js module for manipulating extended attributes.

Latest version **0.4.0** (published 2021-05-11) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2021-05-11 |
| First published | 2014-01-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 32.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 71 |
| Maintainers | linusu |

## Links

- npm: https://www.npmjs.com/package/fs-xattr
- Repository: https://github.com/LinusU/fs-xattr
- Homepage: https://github.com/LinusU/fs-xattr#readme
- Issues: https://github.com/LinusU/fs-xattr/issues
- npm.io page: https://npm.io/package/fs-xattr

## Recent versions

- 0.4.0 (latest) — 2021-05-11
- 0.3.1 — 2020-04-13
- 0.3.0 — 2019-05-09
- 0.2.1 — 2018-03-12
- 0.2.0 — 2017-08-13
- 0.1.17 — 2017-08-07
- 0.1.16 — 2017-08-07
- 0.1.15 — 2016-12-25
- 0.1.14 — 2016-05-04
- 0.1.13 — 2016-05-03
- 0.1.12 — 2016-05-02
- 0.1.10 — 2015-08-16
- 0.1.11 — 2015-08-16
- 0.1.9 — 2015-08-13
- 0.1.8 — 2015-08-03
- … 8 more at https://npm.io/package/fs-xattr/versions

## README

# fs-xattr

Node.js module for manipulating extended attributes.

There are already some libraries for this, why use `fs-xattr`?

- Very useful errors
- No limits on value size
- Clean and easy api
- Proper asynchronous implementation

## Installation

```sh
npm install --save fs-xattr
```

## Usage

```javascript
import { getAttribute, setAttribute } from 'fs-xattr'

await setAttribute('index.js', 'user.linusu.test', 'Hello, World!')

console.log(await getAttribute('index.js', 'user.linusu.test'))
//=> Hello, World!
```

## API

### `getAttribute(path, attr)`

- `path` (`string`, required)
- `attr` (`string`, required)
- returns `Promise<Buffer>` - a `Promise` that will resolve with the value of the attribute.

Get extended attribute `attr` from file at `path`.

### `getAttributeSync(path, attr)`

- `path` (`string`, required)
- `attr` (`string`, required)
- returns `Buffer`

Synchronous version of `getAttribute`.

### `setAttribute(path, attr, value)`

- `path` (`string`, required)
- `attr` (`string`, required)
- `value` (`Buffer` or `string`, required)
- returns `Promise<void>` - a `Promise` that will resolve when the value has been set.

Set extended attribute `attr` to `value` on file at `path`.

### `setAttributeSync(path, attr, value)`

- `path` (`string`, required)
- `attr` (`string`, required)
- `value` (`Buffer` or `string`, required)

Synchronous version of `setAttribute`.

### `removeAttribute(path, attr)`

- `path` (`string`, required)
- `attr` (`string`, required)
- returns `Promise<void>` - a `Promise` that will resolve when the value has been removed.

Remove extended attribute `attr` on file at `path`.

### `removeAttributeSync(path, attr)`

- `path` (`string`, required)
- `attr` (`string`, required)

Synchronous version of `removeAttribute`.

### `listAttributes(path)`

- `path` (`string`, required)
- returns `Promise<Array<string>>` - a `Promise` that will resolve with an array of strings, e.g. `['user.linusu.test', 'com.apple.FinderInfo']`.

List all attributes on file at `path`.

### `listAttributesSync(path)`

- `path` (`string`, required)
- returns `Array<string>`

Synchronous version of `listAttributes`.

## Namespaces

For the large majority of Linux filesystem there are currently 4 supported namespaces (`user`, `trusted`, `security`, and `system`) you can use. Some other systems, like FreeBSD have only 2 (`user` and `system`).

Be sure to use a namespace that is appropriate for your supported platforms. You can read more about this in [the "Extended File Attributes" Wikipedia article](https://en.wikipedia.org/wiki/Extended_file_attributes#Implementations).

Using a namespace like `com.linusu.test` would work on macOS, but would give you the following error on Debian Linux:

> Error \[ENOTSUP]: The file system does not support extended attributes or has the feature disabled.

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