Skip to content

Commit 18015df

Browse files
committed
fix: Documentation
1 parent 1de4401 commit 18015df

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
11
# Binary Reader
22
A binary reader package to read binary data.
3+
4+
## Add Package
5+
```
6+
deno add jsr:@typescriptplayground/binary-reader
7+
```
8+
9+
## Usage
10+
```ts
11+
import {BinaryReader} from "@typescriptplayground/binary-reader";
12+
13+
const dataToRead = new Uint8Array([1,2,3,4])
14+
15+
const reader = new BinaryReader(dataToRead.buffer);
16+
17+
console.log(reader.read(2)) // ArrayBuffer { [Uint8Contents]: <01 02>, byteLength: 2 }
18+
19+
console.log(reader.bufferLeft.byteLength) // 2
20+
21+
console.log(reader.readInt16()) // 772
22+
23+
console.log(reader.bufferLeft.byteLength) // 0
24+
```

deno.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typescriptplayground/binary-reader",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"license": "./LICENSE",
55
"exports": "./src/index.ts",
66
"tasks": {

src/binary_reader.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import DataReader from "./data_reader.ts";
33
/**
44
* This class represents a binary reader.
55
*
6+
* @example
7+
* ```
8+
* const dataToRead = new Uint8Array([1,2,3,4]);
9+
*
10+
* const reader = new BinaryReader(dataToRead.buffer);
11+
*
12+
* console.log(reader.read(2)); // ArrayBuffer { [Uint8Contents]: <01 02>, byteLength: 2 }
13+
* console.log(reader.bufferLeft.byteLength) // 2
14+
* ```
15+
*
616
* @extends DataReader
717
*/
818
export default class BinaryReader extends DataReader {

src/data_reader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* This class represents a binary reader. It is similar to DataView but has an internal pointer to
2+
* This class represents a data reader. It is similar to DataView but has an internal pointer to
33
* automatically pop the bytes that have been already read.
44
*/
55
export default class DataReader {

0 commit comments

Comments
 (0)