# zzz.skein

> A tool for data communication on TCP, etc...

Latest version **0.0.2** (published 2019-02-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install zzz.skein
pnpm add zzz.skein
yarn add zzz.skein
bun add zzz.skein
```

## 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.0.2 |
| Published | 2019-02-26 |
| First published | 2019-02-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | www.z3.guru |
| Maintainers | z3guru |

## Links

- npm: https://www.npmjs.com/package/zzz.skein
- Repository: https://github.com/z3guru/zzz.skein
- Homepage: https://github.com/z3guru/zzz.skein#readme
- Issues: https://github.com/z3guru/zzz.skein/issues
- npm.io page: https://npm.io/package/zzz.skein

## Recent versions

- 0.0.2 (latest) — 2019-02-26
- 0.0.1 — 2019-02-22

## README

# zzz.skein

[![NPM version](http://img.shields.io/npm/v/zzz.skein.svg)](https://www.npmjs.org/package/zzz.skein)


### Description
    
Skein is a library like "java.nio.ByteBuffer" of java. 
In data communication, a module should efficiently manipulate byte streams. 
Because allocating and releasing memory is a costly task. 

Skein provides functions to reuse "Buffer" in node.js, so reducing overheads.
Function definitions referenced "java.nio.ByteBuffer" of java.

### Installation

npm install skein

# Documents

### mark, position, limit, capacity

Skein uses some attributes for manipulating "Buffer" of Node.

0 <= mark <= position <= limit <= capacity

* capacity: a total size of "Buffer", size == bytes count. readonly
* limit : max index {position} can reach.
* position: index of "Buffer" to be read or written
* mark : when reset {position}, this value will be assigned to {position}

### allocate, wrap

.allocate(), .wrap() are static functions that initialize "Buffer".
```
let buf = Skein.allocate(1024)
```
{buf} has 1024 bytes "Buffer". .allocate() function set attributes, capacity=1024, limit=1024, position=0, mark=0
```
let buf = Skein.wrap([0x00, 0x01, 0x02, 0x03]);
```
{buf} has 4 bytes "Buffer" and it contains [0x00, 0x01, 0x02, 0x03]. Attributes are, capacity=4, limit=4, position=0, mark=0

### get, put

You can read or write a byte from Skein by calling get(), put().

let buf = Skein.wrap([0x00, 0x01, 0x02, 0x03]);
let b = buf.get();

The variable 'b' has 0x00. and position=1 where you can read or write next.
```
b = buf.get()  // b=0x01, position=2
b = buf.get()  // b=0x02, position=3
b = buf.get()  // b=0x03, position=4
b = buf.get()  // overflow !!!,  next position=5 > limit=4
```

The above codes show position's role, the position has index you can read next. 
The last line is error(overflow), because next position 5 is over limit.

put() same as get()...

```
let buf = Skein.allocate(4);
buf.put(0x00);  // buf contains [0x00,,,]  position=1
buf.put(0x01);  // buf contains [0x00,0x01,,]  position=2
buf.put(0x02);  // buf contains [0x00,0x01,0x02,]  position=3
buf.put(0x03);  // buf contains [0x00,0x01,0x02,0x03]  position=4
buf.put(0x04);  // overflow !!!
```

### flip()

flip() set {limit} to current {position} and set {position},{mark} to 0.
```
let buf = Skein.allocate(4);  // position=0, limit=4
buf.put(0x00);
buf.put(0x01);
buf.put(0x02);      // position=3, limit=4

buf.flip();         // position=0, limit=3

let b = buf.get();  // b = 0x00
let b = buf.get();  // b = 0x01
let b = buf.get();  // b = 0x02
let b = buf.get();  // overflow !!!   next position=4 > limit=3
``` 
In the above codes, flip() makes Skein to get the previous put data.


### rewind(), clear()

rewind() only set {position},{mark} to 0. It may be used to read data again.

clear() set {limit} to {capacity} and set {position},{mark} to 0.
It makes Skein to be cleared.

### mark(), reset()

mark() set {mark} to current {position}

reset() set {position} to {mark}


### compact()

The bytes between the buffer's current position and its limit, if any, are copied to the beginning of the buffer.
compact() set {position} to next index of the bytes and set {limit} to {capacity}

```
let buf = Skein.allocate(10);  // position=0, limit=10
buf.put(0x00);
buf.put(0x01);
buf.put(0x02);
buf.put(0x03);
buf.put(0x04);      // position=5, limit=10   
// [0x00,0x01,0x02,0x03,0x04,,,,,]

buf.flip();         // position=0, limit=5

let b = buf.get();  // b = 0x00
let b = buf.get();  // b = 0x01
let b = buf.get();  // b = 0x02   // position=3, limit=5
// [0x00,0x01,0x02,0x03,0x04,,,,,]

buf.compact();      // position=2, limit=10
// [0x03,0x04,,,,,,,,]

buf.put(0x05);      // position=3, limit=10
// [0x03,0x04,0x05,,,,,,,]

```

### attributes

* capacity: a total size of "Buffer", size == bytes count. readonly
* limit : max index {position} can reach.
* position: index of "Buffer" to be read or written
* buf : raw "Buffer"
* remaining : a count of remain bytes = {limit} - {position}
* hasRemaining : whether remaining > 0 or not

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