# dat-encoding

> Encode and decode Dat links

Latest version **5.0.2** (published 2022-01-06) · MIT license · 0 weekly downloads

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

## Install

```sh
npm install dat-encoding
pnpm add dat-encoding
yarn add dat-encoding
bun add dat-encoding
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 5.0.2 |
| Published | 2022-01-06 |
| First published | 2016-06-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Maintainers | leichtgewicht, the-real-dk, pfrazee, frando, cblgh, ninabreznik, rangermauve, serapath, zootella, jhand, juliangruber |

## Links

- npm: https://www.npmjs.com/package/dat-encoding
- Repository: https://github.com/juliangruber/dat-encoding
- Homepage: https://github.com/juliangruber/dat-encoding#readme
- Issues: https://github.com/juliangruber/dat-encoding/issues
- npm.io page: https://npm.io/package/dat-encoding

## Dependencies (1)

- [safe-buffer](https://npm.io/package/safe-buffer.md) ^5.0.1

## Recent versions

- 5.0.2 (latest) — 2022-01-06
- 5.0.1 — 2017-12-11
- 5.0.0 — 2017-12-04
- 4.0.2 — 2017-02-08
- 4.0.1 — 2016-12-21
- 4.0.0 — 2016-12-20
- 3.0.2 — 2016-12-10
- 3.0.1 — 2016-09-24
- 3.0.0 — 2016-09-13
- 2.1.0 — 2016-09-12
- 2.0.2 — 2016-07-01
- 2.0.1 — 2016-06-20
- 2.0.0 — 2016-06-20
- 1.2.0 — 2016-06-20
- 1.1.2 — 2016-06-17
- … 4 more at https://npm.io/package/dat-encoding/versions

## README

[![deprecated](http://badges.github.io/stability-badges/dist/deprecated.svg)](https://github.com/hyperswarm/replicator) See [abstract-encoding](https://github.com/mafintosh/abstract-encoding) and [compact-encoding](https://github.com/compact-encoding) for similar functionality. 

More info on active projects and modules at [dat-ecosystem.org](https://dat-ecosystem.org/) <img src="https://i.imgur.com/qZWlO1y.jpg" width="30" height="30" /> 

---

# dat-encoding

[Dat](http://dat-data.com/)'s way of encoding and decoding dat links.

[![Build Status](https://travis-ci.org/juliangruber/dat-encoding.svg?branch=master)](https://travis-ci.org/juliangruber/dat-encoding)

## Example

```js
var encoding = require('dat-encoding')

var link = '6161616161616161616161616161616161616161616161616161616161616161'
var buf = encoding.decode(link)
console.log('%s -> %s', link, buf)
console.log('%s -> %s', buf, encoding.encode(buf))
```

## API

### .encode(buf)
### .toStr(buf)

Encode `buf` into a hex string. Throws if `buf` isn't 32 bytes of length.

If `buf` is already a string, checks if it's valid and returns it.

### .decode(str)
### .toBuf(str)

Decode `str` into its binary representation. Also supports `dat://` and `dat.com/` links. Throws if the raw link isn't 64 bytes of base64.

If `str` is already a buffer, checks if it's valid and returns it.

## License

MIT

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