Commit d67578621cc43f2639bdd03d88b77e2175738937
add tests
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 10/18/2017, 9:23:26 PM
Parent: 18f9faec031b7d134dcbab1ebf63409aea719dd6
Files changed
README.md | changed |
tests/index.js | added |
README.md | ||
---|---|---|
@@ -23,6 +23,32 @@ | ||
23 | 23 … | ``` |
24 | 24 … | |
25 | 25 … | # API |
26 | 26 … | |
27 … | +## constructor | |
28 … | + | |
29 … | +Creates a new instance of a pipe | |
30 … | + | |
31 … | +**Parameters** | |
32 … | + | |
33 … | +- `buf` **[Buffer](https://nodejs.org/api/buffer.html)** an buffer to start with (optional, default `Buffer.from([])`) | |
34 … | + | |
35 … | +## read | |
36 … | + | |
37 … | +read `num` number of bytes from the pipe | |
38 … | + | |
39 … | +**Parameters** | |
40 … | + | |
41 … | +- `num` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** | |
42 … | + | |
43 … | +Returns **[Buffer](https://nodejs.org/api/buffer.html)** | |
44 … | + | |
45 … | +## write | |
46 … | + | |
47 … | +Wites a buffer to the pipe | |
48 … | + | |
49 … | +**Parameters** | |
50 … | + | |
51 … | +- `buf` **[Buffer](https://nodejs.org/api/buffer.html)** | |
52 … | + | |
27 | 53 … | # LICENSE |
28 | 54 … | [MPL-2.0](https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2)) |
tests/index.js | ||
---|---|---|
@@ -1,0 +1,19 @@ | ||
1 … | +const tape = require('tape') | |
2 … | +const Pipe = require('../') | |
3 … | + | |
4 … | +tape('tests', t => { | |
5 … | + let p = new Pipe(Buffer.from([1, 2, 3, 4])) | |
6 … | + p.write(Buffer.from([99])) | |
7 … | + | |
8 … | + t.deepEquals(p.buffer, Buffer.from([1, 2, 3, 4, 99])) | |
9 … | + | |
10 … | + const buf = p.read(3) | |
11 … | + | |
12 … | + t.deepEquals(buf, Buffer.from([1, 2, 3])) | |
13 … | + | |
14 … | + p = new Pipe() | |
15 … | + p.write(Buffer.from([99])) | |
16 … | + | |
17 … | + t.deepEquals(p.buffer, Buffer.from([99])) | |
18 … | + t.end() | |
19 … | +}) |
Built with git-ssb-web