Skip to content

Commit 984d690

Browse files
committed
logo, readme
1 parent 612b86e commit 984d690

File tree

3 files changed

+11
-93
lines changed

3 files changed

+11
-93
lines changed

README.md

Lines changed: 11 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -3,112 +3,30 @@
33
</div>
44

55
```bash
6-
npm i @hazae41/binary
6+
npm i @hazae41/future
77
```
88

9-
[**Node Package 📦**](https://www.npmjs.com/package/@hazae41/binary)
9+
[**Node Package 📦**](https://www.npmjs.com/package/@hazae41/future)
1010

1111
## Features
1212

1313
### Current features
1414
- 100% TypeScript and ESM
1515
- No external dependencies
1616
- Unit-tested
17-
- Zero-copy reading and writing
1817

1918
## Usage
2019

21-
### Cursor
22-
23-
#### Writing
24-
2520
```typescript
26-
const cursor = Cursor.allocUnsafe(1024)
27-
28-
cursor.writeUint8(123)
29-
cursor.writeUint16(1234)
30-
31-
console.log(cursor.offset) // 3
32-
```
33-
34-
#### Reading
35-
36-
```typescript
37-
const bytes = new Uint8Array(/*...*/)
38-
const cursor = new Cursor(bytes)
39-
40-
const uint8 = cursor.readUint8()
41-
const uint16 = cursor.readUint16()
42-
43-
console.log(cursor.offset) // 3
44-
```
21+
const future = new Future<void, unknown>()
4522

46-
### Binary data types
47-
48-
#### Writable
49-
50-
```typescript
51-
class MyObject implements Writable {
52-
53-
constructor(
54-
readonly x: number,
55-
readonly y: number
56-
) {}
57-
58-
size() {
59-
return 1 + 2
60-
}
61-
62-
write(cursor: Cursor) {
63-
cursor.writeUint8(this.x)
64-
cursor.writeUint16(this.y)
65-
}
23+
const okTimeout = setTimeout(() => future.ok(), 1000)
24+
const errTimeout = setTimeout(() => future.err(), 2000)
6625

26+
try {
27+
await future.promise
28+
} finally {
29+
clearTimeout(okTimeout)
30+
clearTimeout(errTimeout)
6731
}
68-
```
69-
70-
```typescript
71-
const myobject = new MyObject(1, 515)
72-
const bytes = Writable.toBytes(myobject) // Uint8Array([1, 2, 3])
73-
```
74-
75-
#### Readable
76-
77-
```typescript
78-
class MyObject {
79-
80-
constructor(
81-
readonly x: number,
82-
readonly y: number
83-
) {}
84-
85-
static read(cursor: Cursor) {
86-
const x = cursor.readUint8()
87-
const y = cursor.readUint16()
88-
89-
return new this(x, y)
90-
}
91-
92-
}
93-
```
94-
95-
```typescript
96-
const bytes = new Uint8Array([1, 2, 3])
97-
const myobject = Readable.fromBytes(MyObject, bytes) // MyObject(1, 515)
98-
```
99-
100-
#### Opaque
101-
102-
This is a binary data type that just holds bytes, it can be used when a binary data type is required
103-
104-
```typescript
105-
const bytes = new Uint8Array([1, 2, 3])
106-
const opaque = Readable.fromBytes(SafeOpaque, bytes) // Opaque(Uint8Array([1, 2, 3]))
107-
const myobject = opaque.into(MyObject) // MyObject(1, 515)
108-
```
109-
110-
```typescript
111-
const myobject = new MyObject(1, 515)
112-
const opaque = Opaque.from(myobject) // Opaque(Uint8Array([1, 2, 3]))
113-
const bytes = Writable.toBytes(opaque) // Uint8Array([1, 2, 3])
114-
```
32+
```

assets/banner.psd

-296 KB
Binary file not shown.

assets/future.png

39.5 KB
Loading

0 commit comments

Comments
 (0)