@k67/kaitai-struct-ts 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Fabiano Pinto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,188 @@
1
+ # kaitai-struct-ts
2
+
3
+ [![npm version](https://badge.fury.io/js/%40k67%2Fkaitai-struct-ts.svg)](https://www.npmjs.com/package/@k67/kaitai-struct-ts)
4
+ [![CI](https://github.com/fabianopinto/kaitai-struct-ts/workflows/CI/badge.svg)](https://github.com/fabianopinto/kaitai-struct-ts/actions)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue.svg)](https://www.typescriptlang.org/)
7
+ [![Node.js](https://img.shields.io/badge/Node.js-18%2B-green.svg)](https://nodejs.org/)
8
+
9
+ A **runtime interpreter** for [Kaitai Struct](https://kaitai.io/) binary format definitions in TypeScript.
10
+
11
+ Parse any binary data format by providing a `.ksy` (Kaitai Struct YAML) definition file - no compilation step required!
12
+
13
+ ## Features
14
+
15
+ - ๐Ÿš€ **Runtime interpretation** - No code generation needed
16
+ - ๐Ÿ“ฆ **Zero dependencies** (runtime) - Only YAML parser for development
17
+ - ๐ŸŽฏ **TypeScript native** - Full type safety and IntelliSense support
18
+ - ๐ŸŒ **Universal** - Works in Node.js and browsers
19
+ - ๐Ÿงช **Well tested** - Comprehensive test coverage
20
+ - ๐Ÿ“– **Well documented** - Clear API and examples
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ npm install @k67/kaitai-struct-ts
26
+ # or
27
+ pnpm add @k67/kaitai-struct-ts
28
+ # or
29
+ yarn add @k67/kaitai-struct-ts
30
+ ```
31
+
32
+ ## Quick Start
33
+
34
+ ```typescript
35
+ import { parse, KaitaiStream } from '@k67/kaitai-struct-ts'
36
+ import { readFileSync } from 'fs'
37
+
38
+ // Load your .ksy definition
39
+ const ksyDefinition = `
40
+ meta:
41
+ id: my_format
42
+ endian: le
43
+ seq:
44
+ - id: magic
45
+ contents: [0x4D, 0x59, 0x46, 0x4D]
46
+ - id: version
47
+ type: u2
48
+ - id: name
49
+ type: str
50
+ size: 32
51
+ encoding: UTF-8
52
+ `
53
+
54
+ // Load your binary data
55
+ const binaryData = readFileSync('data.bin')
56
+
57
+ // Parse!
58
+ const result = await parse(ksyDefinition, binaryData)
59
+
60
+ console.log(result.version) // Access parsed fields
61
+ console.log(result.name)
62
+ ```
63
+
64
+ ## Current Status
65
+
66
+ **Phase 2 (Core Features) - In Progress**
67
+
68
+ ### Completed
69
+ - [x] Project setup and configuration
70
+ - [x] KaitaiStream implementation (all primitive types)
71
+ - [x] KSY parser with validation
72
+ - [x] Type interpreter (basic parsing)
73
+ - [x] Support for fixed-size structures
74
+ - [x] Nested user-defined types
75
+ - [x] Repetitions (expr, eos)
76
+ - [x] Contents validation
77
+ - [x] Comprehensive tests (58 tests passing)
78
+
79
+ ### In Progress
80
+ - [ ] Expression evaluator
81
+ - [ ] Conditionals (if)
82
+ - [ ] Enums
83
+ - [ ] repeat-until
84
+
85
+ See [PROJECT_DESIGN.md](./PROJECT_DESIGN.md) for detailed roadmap and [ARCHITECTURE.md](./docs/ARCHITECTURE.md) for architecture diagrams.
86
+
87
+ ## API Documentation
88
+
89
+ ### `parse(ksy: string, buffer: ArrayBuffer | Uint8Array, options?: ParseOptions): Record<string, unknown>`
90
+
91
+ Parse binary data using a Kaitai Struct definition.
92
+
93
+ **Parameters:**
94
+ - `ksy` - YAML string containing the .ksy definition
95
+ - `buffer` - Binary data to parse
96
+ - `options` - Optional parsing options (validate, strict)
97
+
98
+ **Returns:** Parsed object with fields defined in the .ksy file
99
+
100
+ **Example:**
101
+ ```typescript
102
+ import { parse } from 'kaitai-struct-ts'
103
+
104
+ const result = parse(ksyYaml, binaryData, { validate: true })
105
+ console.log(result.fieldName)
106
+ ```
107
+
108
+ ### `KaitaiStream`
109
+
110
+ Low-level binary stream reader.
111
+
112
+ ```typescript
113
+ const stream = new KaitaiStream(buffer)
114
+ const value = stream.readU4le() // Read 4-byte unsigned little-endian integer
115
+ ```
116
+
117
+ See [API Documentation](./docs/api.md) for complete reference (coming soon).
118
+
119
+ ## Examples
120
+
121
+ Check the [examples](./examples) directory for more usage examples:
122
+
123
+ - Basic struct parsing
124
+ - Working with enums
125
+ - Conditional parsing
126
+ - Repetitions
127
+
128
+ ## Development
129
+
130
+ ```bash
131
+ # Install dependencies
132
+ pnpm install
133
+
134
+ # Build
135
+ pnpm build
136
+
137
+ # Run tests
138
+ pnpm test
139
+
140
+ # Run tests with UI
141
+ pnpm test:ui
142
+
143
+ # Test coverage
144
+ pnpm test:coverage
145
+
146
+ # Lint
147
+ pnpm lint
148
+
149
+ # Format
150
+ pnpm format
151
+ ```
152
+
153
+ ## Roadmap
154
+
155
+ ### Phase 1: Foundation (MVP) - Current
156
+ - Basic parsing capability
157
+ - Fixed-size structures
158
+ - Primitive types
159
+
160
+ ### Phase 2: Core Features
161
+ - Expression evaluator
162
+ - Conditionals and enums
163
+ - Repetitions
164
+ - Instances
165
+
166
+ ### Phase 3: Advanced Features
167
+ - Substreams and processing
168
+ - Bit-sized integers
169
+ - Imports
170
+ - Full spec compliance
171
+
172
+ ## Contributing
173
+
174
+ Contributions are welcome! Please read our [Contributing Guidelines](./CONTRIBUTING.md) first.
175
+
176
+ ## License
177
+
178
+ MIT ยฉ Fabiano Pinto
179
+
180
+ ## Related Projects
181
+
182
+ - [Kaitai Struct](https://kaitai.io/) - Official Kaitai Struct project
183
+ - [kaitai-struct-compiler](https://github.com/kaitai-io/kaitai_struct_compiler) - Official compiler
184
+ - [Format Gallery](https://formats.kaitai.io/) - Collection of .ksy format definitions
185
+
186
+ ## Acknowledgments
187
+
188
+ This project implements the [Kaitai Struct specification](https://doc.kaitai.io/) created by the Kaitai Struct team.