Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dat-ecosystem-archive/dat-encoding
Dat's way of encoding and decoding dat links [ DEPRECATED - see https://github.com/mafintosh/abstract-encoding and https://github.com/compact-encoding for similar functionality. More info on active projects and modules at https://dat-ecosystem.org/ ]
https://github.com/dat-ecosystem-archive/dat-encoding
Last synced: 10 days ago
JSON representation
Dat's way of encoding and decoding dat links [ DEPRECATED - see https://github.com/mafintosh/abstract-encoding and https://github.com/compact-encoding for similar functionality. More info on active projects and modules at https://dat-ecosystem.org/ ]
- Host: GitHub
- URL: https://github.com/dat-ecosystem-archive/dat-encoding
- Owner: dat-ecosystem-archive
- License: mit
- Archived: true
- Created: 2016-06-17T11:26:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-01-06T01:59:28.000Z (almost 3 years ago)
- Last Synced: 2024-05-16T13:14:54.204Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 50.8 KB
- Stars: 19
- Watchers: 4
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-dat - dat-encoding - encoder and decoder that supports the dat url-scheme (Using Dat / Dat Link Utilties)
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/)
---
# 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