https://github.com/incognitojam/tiny-struct
A TypeScript library for parsing binary data structures
https://github.com/incognitojam/tiny-struct
Last synced: 2 months ago
JSON representation
A TypeScript library for parsing binary data structures
- Host: GitHub
- URL: https://github.com/incognitojam/tiny-struct
- Owner: incognitojam
- License: mit
- Created: 2025-03-13T14:53:36.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-03-16T21:35:24.000Z (9 months ago)
- Last Synced: 2025-03-16T22:22:48.079Z (9 months ago)
- Language: TypeScript
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tiny-struct
A minimal TypeScript library for parsing and building binary data structures.
## Usage
```typescript
import { struct, bytes, uint32, uint64 } from "tiny-struct";
// Define a struct
const GPTHeader = struct("GPTHeader", {
signature: bytes(8),
revision: uint32(),
headerSize: uint32(),
currentLba: uint64(),
// more fields...
}, {
littleEndian: true
});
// Parse binary data
const header = GPTHeader.from(buffer);
console.log("Signature:", new TextDecoder().decode(header.signature));
// Modify it
header.revision = 0x00020000;
const modifiedBuffer = header.$toBuffer();
// Or create new data
const newBuffer = GPTHeader.to({
signature: new TextEncoder().encode("EFI PART"),
revision: 0x00010000,
headerSize: 92,
currentLba: 1n,
// more fields...
});
```
## License
MIT