@k67/kaitai-struct-ts 0.7.3 → 0.8.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/README.md +19 -6
- package/dist/cli.js +16 -3
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +19 -21
package/README.md
CHANGED
@@ -3,13 +3,14 @@
|
|
3
3
|
|
4
4
|
# kaitai-struct-ts
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
[](https://www.npmjs.com/package/@k67/kaitai-struct-ts)
|
7
|
+
[](https://github.com/fabianopinto/kaitai-struct-ts/actions)
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
9
|
+
[](https://www.typescriptlang.org/)
|
10
|
+
[](https://nodejs.org/)
|
11
|
+
|
12
|
+
**A runtime interpreter for [Kaitai Struct](https://kaitai.io/) binary format definitions in TypeScript.**
|
11
13
|
|
12
|
-
**A runtime interpreter for [Kaitai Struct](https://kaitai.io/) binary format definitions in TypeScript.**
|
13
14
|
</div>
|
14
15
|
|
15
16
|
---
|
@@ -19,6 +20,7 @@ Parse any binary data format by providing a `.ksy` (Kaitai Struct YAML) definiti
|
|
19
20
|
## Features
|
20
21
|
|
21
22
|
### Core Features
|
23
|
+
|
22
24
|
- 🚀 **Runtime interpretation** - No code generation needed
|
23
25
|
- 📦 **Zero dependencies** (runtime) - Only YAML parser for development
|
24
26
|
- 🎯 **TypeScript native** - Full type safety and IntelliSense support
|
@@ -27,6 +29,7 @@ Parse any binary data format by providing a `.ksy` (Kaitai Struct YAML) definiti
|
|
27
29
|
- 📖 **Well documented** - Clear API and examples
|
28
30
|
|
29
31
|
### Advanced Features
|
32
|
+
|
30
33
|
- ⚡ **Expression evaluation** - Full support for Kaitai expressions
|
31
34
|
- 🔀 **Switch/case types** - Dynamic type selection based on data
|
32
35
|
- 💎 **Instances** - Lazy-evaluated fields with caching
|
@@ -110,6 +113,7 @@ console.log(result.name)
|
|
110
113
|
**Completion:** ~95% toward v1.0.0
|
111
114
|
|
112
115
|
### ✅ Fully Implemented
|
116
|
+
|
113
117
|
- **Core Runtime** - Complete binary stream reader with all primitive types
|
114
118
|
- **KSY Parser** - Full YAML parser with schema validation
|
115
119
|
- **Type Interpreter** - Execute schemas against binary data
|
@@ -120,6 +124,7 @@ console.log(result.name)
|
|
120
124
|
- **Documentation** - Complete user and developer documentation
|
121
125
|
|
122
126
|
### 🔄 Remaining for v1.0.0
|
127
|
+
|
123
128
|
- Substream processing (zlib, encryption)
|
124
129
|
- Type imports across files
|
125
130
|
- Additional performance optimizations
|
@@ -133,6 +138,7 @@ See [docs/development/PROGRESS.md](./docs/development/PROGRESS.md) for detailed
|
|
133
138
|
Parse binary data using a Kaitai Struct definition.
|
134
139
|
|
135
140
|
**Parameters:**
|
141
|
+
|
136
142
|
- `ksy` - YAML string containing the .ksy definition
|
137
143
|
- `buffer` - Binary data to parse
|
138
144
|
- `options` - Optional parsing options (validate, strict)
|
@@ -140,6 +146,7 @@ Parse binary data using a Kaitai Struct definition.
|
|
140
146
|
**Returns:** Parsed object with fields defined in the .ksy file
|
141
147
|
|
142
148
|
**Example:**
|
149
|
+
|
143
150
|
```typescript
|
144
151
|
import { parse } from 'kaitai-struct-ts'
|
145
152
|
|
@@ -176,6 +183,7 @@ kaitai format.ksy data.bin --quiet # Quiet mode
|
|
176
183
|
**📖 Full CLI Documentation:** [docs/CLI.md](./docs/CLI.md)
|
177
184
|
|
178
185
|
**Quick Reference:**
|
186
|
+
|
179
187
|
- `-o, --output <file>` - Write to file
|
180
188
|
- `--field <path>` - Extract specific field
|
181
189
|
- `-q, --quiet` - Suppress progress messages
|
@@ -219,6 +227,7 @@ pnpm format
|
|
219
227
|
## Roadmap
|
220
228
|
|
221
229
|
### ✅ Phase 1: Foundation (v0.1.0) - Complete
|
230
|
+
|
222
231
|
- ✅ Binary stream reader (KaitaiStream)
|
223
232
|
- ✅ All primitive types (u1-u8, s1-s8, f4, f8)
|
224
233
|
- ✅ String encoding (UTF-8, ASCII, Latin-1, UTF-16)
|
@@ -226,6 +235,7 @@ pnpm format
|
|
226
235
|
- ✅ Error handling system
|
227
236
|
|
228
237
|
### ✅ Phase 2: Core Features (v0.2.0-v0.4.0) - Complete
|
238
|
+
|
229
239
|
- ✅ KSY parser with validation
|
230
240
|
- ✅ Type interpreter
|
231
241
|
- ✅ Expression evaluator (full Kaitai expression language)
|
@@ -235,6 +245,7 @@ pnpm format
|
|
235
245
|
- ✅ Nested user-defined types
|
236
246
|
|
237
247
|
### ✅ Phase 3: Advanced Features (v0.5.0-v0.6.0) - Complete
|
248
|
+
|
238
249
|
- ✅ Switch/case type selection
|
239
250
|
- ✅ Instances (lazy-evaluated fields with caching)
|
240
251
|
- ✅ Parametric types
|
@@ -243,11 +254,13 @@ pnpm format
|
|
243
254
|
- ✅ Processing framework (ready for zlib/encryption)
|
244
255
|
|
245
256
|
### ✅ Phase 4: CLI & Polish (v0.7.0) - Complete
|
257
|
+
|
246
258
|
- ✅ Command-line interface
|
247
259
|
- ✅ Documentation reorganization
|
248
260
|
- ✅ Production-ready release
|
249
261
|
|
250
262
|
### 🔄 Phase 5: v1.0.0 - Final Polish (In Progress)
|
263
|
+
|
251
264
|
- ⏳ Processing implementations (zlib, encryption)
|
252
265
|
- ⏳ Type imports across files
|
253
266
|
- ⏳ Additional performance optimizations
|
package/dist/cli.js
CHANGED
@@ -2313,7 +2313,14 @@ var TypeInterpreter = class _TypeInterpreter {
|
|
2313
2313
|
return this.readFloat(base, endian, stream);
|
2314
2314
|
}
|
2315
2315
|
if (isStringType(type)) {
|
2316
|
-
|
2316
|
+
const encoding = this.schema.meta?.encoding || "UTF-8";
|
2317
|
+
if (type === "strz") {
|
2318
|
+
return stream.readStrz(encoding, 0, false, true, true);
|
2319
|
+
} else if (type === "str") {
|
2320
|
+
throw new ParseError(
|
2321
|
+
"str type requires size, size-eos, or terminator attribute"
|
2322
|
+
);
|
2323
|
+
}
|
2317
2324
|
}
|
2318
2325
|
throw new ParseError(`Unknown built-in type: ${type}`);
|
2319
2326
|
}
|
@@ -2555,11 +2562,17 @@ function extractField(obj, path) {
|
|
2555
2562
|
}
|
2556
2563
|
return current;
|
2557
2564
|
}
|
2565
|
+
function jsonReplacer(_key, value) {
|
2566
|
+
if (typeof value === "bigint") {
|
2567
|
+
return value.toString();
|
2568
|
+
}
|
2569
|
+
return value;
|
2570
|
+
}
|
2558
2571
|
function formatOutput(data, format, pretty) {
|
2559
2572
|
if (format === "yaml") {
|
2560
|
-
return JSON.stringify(data,
|
2573
|
+
return JSON.stringify(data, jsonReplacer, 2).replace(/^{$/gm, "").replace(/^}$/gm, "").replace(/^\s*"([^"]+)":\s*/gm, "$1: ").replace(/,$/gm, "");
|
2561
2574
|
}
|
2562
|
-
return pretty ? JSON.stringify(data,
|
2575
|
+
return pretty ? JSON.stringify(data, jsonReplacer, 2) : JSON.stringify(data, jsonReplacer);
|
2563
2576
|
}
|
2564
2577
|
function main() {
|
2565
2578
|
const { options, positional } = parseCliArgs();
|
package/dist/index.js
CHANGED
@@ -2347,7 +2347,14 @@ var TypeInterpreter = class _TypeInterpreter {
|
|
2347
2347
|
return this.readFloat(base, endian, stream);
|
2348
2348
|
}
|
2349
2349
|
if (isStringType(type)) {
|
2350
|
-
|
2350
|
+
const encoding = this.schema.meta?.encoding || "UTF-8";
|
2351
|
+
if (type === "strz") {
|
2352
|
+
return stream.readStrz(encoding, 0, false, true, true);
|
2353
|
+
} else if (type === "str") {
|
2354
|
+
throw new ParseError(
|
2355
|
+
"str type requires size, size-eos, or terminator attribute"
|
2356
|
+
);
|
2357
|
+
}
|
2351
2358
|
}
|
2352
2359
|
throw new ParseError(`Unknown built-in type: ${type}`);
|
2353
2360
|
}
|