@bun-win32/cabinet 1.0.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/AI.md ADDED
@@ -0,0 +1,71 @@
1
+ # AI Guide for @bun-win32/cabinet
2
+
3
+ How to use this package, not what the Win32 API does.
4
+
5
+ ## Usage
6
+
7
+ ```ts
8
+ import Cabinet, { SomeFlag } from '@bun-win32/cabinet';
9
+
10
+ // Methods bind lazily on first call
11
+ const result = Cabinet.SomeFunctionW(arg1, arg2);
12
+
13
+ // Preload: array, single string, or no args (all symbols)
14
+ Cabinet.Preload(['SomeFunctionW', 'AnotherFunction']);
15
+ Cabinet.Preload('SomeFunctionW');
16
+ Cabinet.Preload();
17
+ ```
18
+
19
+ ## Where To Look
20
+
21
+ | Need | Read |
22
+ | --------------------------------- | -------------------- |
23
+ | Find a method or its MS Docs link | `structs/Cabinet.ts` |
24
+ | Find types, enums, constants | `types/Cabinet.ts` |
25
+ | Quick examples | `README.md` |
26
+
27
+ `index.ts` re-exports the class and all types — import from `@bun-win32/cabinet` directly.
28
+
29
+ ## Calling Convention
30
+
31
+ All documented `cabinet.dll` exports are bound. Each method maps 1:1 to its DLL export. Names, parameter names, and order match Microsoft Docs.
32
+
33
+ ### Strings
34
+
35
+ `W` methods take UTF-16LE NUL-terminated buffers. `A` methods take ANSI strings.
36
+
37
+ ```ts
38
+ const wide = Buffer.from('Hello\0', 'utf16le'); // LPCWSTR
39
+ Cabinet.SomeFunctionW(wide.ptr);
40
+
41
+ // Reading a wide string back from a buffer:
42
+ const text = new TextDecoder('utf-16').decode(buf).replace(/\0.*$/, '');
43
+ ```
44
+
45
+ ### Return types
46
+
47
+ - `HANDLE`, `HWND`, etc. → `bigint`
48
+ - `DWORD`, `UINT`, `BOOL`, `INT`, `LONG` → `number`
49
+ - `LPVOID`, `LPWSTR`, etc. → `Pointer`
50
+ - Win32 `BOOL` is `number` (0 or non-zero), **not** JS `boolean`. Do not compare with `=== true`.
51
+
52
+ ### Pointers, handles, out-parameters
53
+
54
+ - **Pointer** params (`LP*`, `P*`, `Pointer`): pass `buffer.ptr` from a caller-allocated `Buffer`.
55
+ - **Handle** params (`HANDLE`, `HWND`, etc.): pass a `bigint` value.
56
+ - **Out-parameters**: allocate a `Buffer`, pass `.ptr`, read the result after the call.
57
+
58
+ ```ts
59
+ const out = Buffer.alloc(4);
60
+ Cabinet.SomeFunction(out.ptr);
61
+ const value = out.readUInt32LE(0);
62
+ ```
63
+
64
+ ### Nullability
65
+
66
+ - `| NULL` in a signature → pass `null` (optional pointer).
67
+ - `| 0n` in a signature → pass `0n` (optional handle).
68
+
69
+ ## Errors and Cleanup
70
+
71
+ Return values are raw. If the Win32 function uses last-error semantics, read via `GetLastError()`. Resource cleanup is your responsibility — same as raw Win32.
package/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # @bun-win32/cabinet
2
+
3
+ Zero-dependency, zero-overhead Win32 Cabinet bindings for [Bun](https://bun.sh) on Windows.
4
+
5
+ ## Overview
6
+
7
+ `@bun-win32/cabinet` exposes the `cabinet.dll` exports using [Bun](https://bun.sh)'s FFI. It provides a single class, `Cabinet`, which lazily binds native symbols on first use. You can optionally preload a subset or all symbols up-front via `Preload()`.
8
+
9
+ The bindings are strongly typed for a smooth DX in TypeScript.
10
+
11
+ ## Features
12
+
13
+ - [Bun](https://bun.sh)-first ergonomics on Windows 10/11.
14
+ - Direct FFI to `cabinet.dll` (Compression API — MSZIP / XPRESS / XPRESS-Huffman / LZMS — plus FCI/FDI Cabinet (.cab) archive creation and extraction).
15
+ - In-source docs in `structs/Cabinet.ts` with links to Microsoft Docs.
16
+ - Lazy binding on first call; optional eager preload (`Cabinet.Preload()`).
17
+ - No wrapper overhead; calls map 1:1 to native APIs.
18
+ - Strongly-typed Win32 aliases (see `types/Cabinet.ts`).
19
+
20
+ ## Requirements
21
+
22
+ - [Bun](https://bun.sh) runtime
23
+ - Windows 10 or later
24
+
25
+ ## Installation
26
+
27
+ ```sh
28
+ bun add @bun-win32/cabinet
29
+ ```
30
+
31
+ ## Quick Start
32
+
33
+ ```ts
34
+ import Cabinet, { COMPRESS_ALGORITHM } from '@bun-win32/cabinet';
35
+
36
+ const input = Buffer.from('compress me '.repeat(64));
37
+
38
+ // Create an XPRESS-Huffman compressor (handle is returned through an out-buffer)
39
+ const hCompressor = Buffer.alloc(8);
40
+ Cabinet.CreateCompressor(COMPRESS_ALGORITHM.COMPRESS_ALGORITHM_XPRESS_HUFF, null, hCompressor.ptr);
41
+ const compressor = hCompressor.readBigUInt64LE(0);
42
+
43
+ // Sizing call: a NULL buffer reports the required size, then compress for real
44
+ const size = Buffer.alloc(8);
45
+ Cabinet.Compress(compressor, input.ptr, BigInt(input.length), null, 0n, size.ptr);
46
+ const compressed = Buffer.alloc(Number(size.readBigUInt64LE(0)));
47
+ Cabinet.Compress(compressor, input.ptr, BigInt(input.length), compressed.ptr, BigInt(compressed.length), size.ptr);
48
+ const compressedSize = Number(size.readBigUInt64LE(0));
49
+ Cabinet.CloseCompressor(compressor);
50
+
51
+ // Decompress back and verify the round trip
52
+ const hDecompressor = Buffer.alloc(8);
53
+ Cabinet.CreateDecompressor(COMPRESS_ALGORITHM.COMPRESS_ALGORITHM_XPRESS_HUFF, null, hDecompressor.ptr);
54
+ const decompressor = hDecompressor.readBigUInt64LE(0);
55
+ const restored = Buffer.alloc(input.length);
56
+ Cabinet.Decompress(decompressor, compressed.ptr, BigInt(compressedSize), restored.ptr, BigInt(restored.length), null);
57
+ Cabinet.CloseDecompressor(decompressor);
58
+
59
+ console.log(`${input.length} → ${compressedSize} bytes · round-trip ok: ${restored.equals(input)}`);
60
+ ```
61
+
62
+ > [!NOTE]
63
+ > AI agents: see `AI.md` for the package binding contract and source-navigation guidance. It explains how to use the package without scanning the entire implementation.
64
+
65
+ ## Examples
66
+
67
+ Run the included examples:
68
+
69
+ ```sh
70
+ # Live algorithm race: MSZIP vs XPRESS vs XPRESS-Huffman vs LZMS, animated
71
+ bun run example/compression-arena.ts
72
+
73
+ # Build a real .cab with FCI, then inspect + extract + verify it with FDI
74
+ bun run example/cabinet-workshop.ts
75
+ ```
76
+
77
+ ## Notes
78
+
79
+ - Either rely on lazy binding or call `Cabinet.Preload()`.
80
+ - Windows only. Bun runtime required.
package/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ import Cabinet from './structs/Cabinet';
2
+
3
+ export * from './types/Cabinet';
4
+ export default Cabinet;
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "author": "Stev Peifer <stev@bell.net>",
3
+ "bugs": {
4
+ "url": "https://github.com/ObscuritySRL/bun-win32/issues"
5
+ },
6
+ "dependencies": {
7
+ "@bun-win32/core": "1.1.2"
8
+ },
9
+ "description": "Zero-dependency, zero-overhead Win32 CABINET bindings for Bun (FFI) on Windows.",
10
+ "devDependencies": {
11
+ "@bun-win32/kernel32": "1.0.21",
12
+ "@types/bun": "latest"
13
+ },
14
+ "exports": {
15
+ ".": "./index.ts"
16
+ },
17
+ "license": "MIT",
18
+ "module": "index.ts",
19
+ "name": "@bun-win32/cabinet",
20
+ "peerDependencies": {
21
+ "typescript": "^5"
22
+ },
23
+ "private": false,
24
+ "homepage": "https://github.com/ObscuritySRL/bun-win32#readme",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git://github.com/ObscuritySRL/bun-win32.git",
28
+ "directory": "packages/cabinet"
29
+ },
30
+ "type": "module",
31
+ "version": "1.0.0",
32
+ "main": "./index.ts",
33
+ "keywords": [
34
+ "bun",
35
+ "ffi",
36
+ "win32",
37
+ "windows",
38
+ "cabinet",
39
+ "bindings",
40
+ "typescript",
41
+ "dll"
42
+ ],
43
+ "files": [
44
+ "AI.md",
45
+ "README.md",
46
+ "index.ts",
47
+ "structs/*.ts",
48
+ "types/*.ts"
49
+ ],
50
+ "sideEffects": false,
51
+ "engines": {
52
+ "bun": ">=1.1.0"
53
+ },
54
+ "scripts": {
55
+ "example:cabinet-workshop": "bun ./example/cabinet-workshop.ts",
56
+ "example:compression-arena": "bun ./example/compression-arena.ts"
57
+ }
58
+ }
@@ -0,0 +1,239 @@
1
+ import { type FFIFunction, FFIType } from 'bun:ffi';
2
+
3
+ import { Win32 } from '@bun-win32/core';
4
+
5
+ import type {
6
+ BOOL,
7
+ COMPRESS_INFORMATION_CLASS,
8
+ COMPRESSOR_HANDLE,
9
+ DECOMPRESSOR_HANDLE,
10
+ DWORD,
11
+ HFCI,
12
+ HFDI,
13
+ INT,
14
+ INT_PTR,
15
+ LPCVOID,
16
+ LPSTR,
17
+ LPVOID,
18
+ NULL,
19
+ PCABINETDLLVERSIONINFO,
20
+ PCCAB,
21
+ PCOMPRESS_ALLOCATION_ROUTINES,
22
+ PCOMPRESSOR_HANDLE,
23
+ PDECOMPRESSOR_HANDLE,
24
+ PERF,
25
+ PFDICABINETINFO,
26
+ PFNALLOC,
27
+ PFNCLOSE,
28
+ PFNFCIALLOC,
29
+ PFNFCICLOSE,
30
+ PFNFCIDELETE,
31
+ PFNFCIFILEPLACED,
32
+ PFNFCIFREE,
33
+ PFNFCIGETNEXTCABINET,
34
+ PFNFCIGETOPENINFO,
35
+ PFNFCIGETTEMPFILE,
36
+ PFNFCIOPEN,
37
+ PFNFCIREAD,
38
+ PFNFCISEEK,
39
+ PFNFCISTATUS,
40
+ PFNFCIWRITE,
41
+ PFNFDIDECRYPT,
42
+ PFNFDINOTIFY,
43
+ PFNFREE,
44
+ PFNOPEN,
45
+ PFNREAD,
46
+ PFNSEEK,
47
+ PFNWRITE,
48
+ PSIZE_T,
49
+ PVOID,
50
+ SIZE_T,
51
+ TCOMP,
52
+ USHORT,
53
+ VOID,
54
+ } from '../types/Cabinet';
55
+
56
+ /**
57
+ * Thin, lazy-loaded FFI bindings for `cabinet.dll`.
58
+ *
59
+ * Each static method corresponds one-to-one with a Win32 export declared in `Symbols`.
60
+ * The first call to a method binds the underlying native symbol via `bun:ffi` and
61
+ * memoizes it on the class for subsequent calls. For bulk, up-front binding, use `Preload`.
62
+ *
63
+ * Symbols are defined with explicit `FFIType` signatures and kept alphabetized.
64
+ * You normally do not access `Symbols` directly; call the static methods or preload
65
+ * a subset for hot paths.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * import Cabinet from './structs/Cabinet';
70
+ *
71
+ * // Lazy: bind on first call
72
+ * const handle = Buffer.alloc(8);
73
+ * Cabinet.CreateCompressor(COMPRESS_ALGORITHM.COMPRESS_ALGORITHM_XPRESS, null, handle.ptr);
74
+ *
75
+ * // Or preload a subset to avoid per-symbol lazy binding cost
76
+ * Cabinet.Preload(['CreateCompressor', 'Compress', 'CloseCompressor']);
77
+ * ```
78
+ */
79
+ class Cabinet extends Win32 {
80
+ protected static override name = 'cabinet.dll';
81
+
82
+ /** @inheritdoc */
83
+ protected static override readonly Symbols = {
84
+ CloseCompressor: { args: [FFIType.u64], returns: FFIType.i32 },
85
+ CloseDecompressor: { args: [FFIType.u64], returns: FFIType.i32 },
86
+ Compress: { args: [FFIType.u64, FFIType.ptr, FFIType.u64, FFIType.ptr, FFIType.u64, FFIType.ptr], returns: FFIType.i32 },
87
+ CreateCompressor: { args: [FFIType.u32, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
88
+ CreateDecompressor: { args: [FFIType.u32, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
89
+ Decompress: { args: [FFIType.u64, FFIType.ptr, FFIType.u64, FFIType.ptr, FFIType.u64, FFIType.ptr], returns: FFIType.i32 },
90
+ DllGetVersion: { args: [FFIType.ptr], returns: FFIType.void },
91
+ FCIAddFile: { args: [FFIType.u64, FFIType.ptr, FFIType.ptr, FFIType.i32, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.u16], returns: FFIType.i32 },
92
+ FCICreate: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.u64 },
93
+ FCIDestroy: { args: [FFIType.u64], returns: FFIType.i32 },
94
+ FCIFlushCabinet: { args: [FFIType.u64, FFIType.i32, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
95
+ FCIFlushFolder: { args: [FFIType.u64, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
96
+ FDICopy: { args: [FFIType.u64, FFIType.ptr, FFIType.ptr, FFIType.i32, FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
97
+ FDICreate: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.i32, FFIType.ptr], returns: FFIType.u64 },
98
+ FDIDestroy: { args: [FFIType.u64], returns: FFIType.i32 },
99
+ FDIIsCabinet: { args: [FFIType.u64, FFIType.i64, FFIType.ptr], returns: FFIType.i32 },
100
+ FDITruncateCabinet: { args: [FFIType.u64, FFIType.ptr, FFIType.u16], returns: FFIType.i32 },
101
+ QueryCompressorInformation: { args: [FFIType.u64, FFIType.u32, FFIType.ptr, FFIType.u64], returns: FFIType.i32 },
102
+ QueryDecompressorInformation: { args: [FFIType.u64, FFIType.u32, FFIType.ptr, FFIType.u64], returns: FFIType.i32 },
103
+ ResetCompressor: { args: [FFIType.u64], returns: FFIType.i32 },
104
+ ResetDecompressor: { args: [FFIType.u64], returns: FFIType.i32 },
105
+ SetCompressorInformation: { args: [FFIType.u64, FFIType.u32, FFIType.ptr, FFIType.u64], returns: FFIType.i32 },
106
+ SetDecompressorInformation: { args: [FFIType.u64, FFIType.u32, FFIType.ptr, FFIType.u64], returns: FFIType.i32 },
107
+ } as const satisfies Record<string, FFIFunction>;
108
+
109
+ // https://learn.microsoft.com/en-us/windows/win32/api/compressapi/nf-compressapi-closecompressor
110
+ public static CloseCompressor(CompressorHandle: COMPRESSOR_HANDLE): BOOL {
111
+ return Cabinet.Load('CloseCompressor')(CompressorHandle);
112
+ }
113
+
114
+ // https://learn.microsoft.com/en-us/windows/win32/api/compressapi/nf-compressapi-closedecompressor
115
+ public static CloseDecompressor(DecompressorHandle: DECOMPRESSOR_HANDLE): BOOL {
116
+ return Cabinet.Load('CloseDecompressor')(DecompressorHandle);
117
+ }
118
+
119
+ // https://learn.microsoft.com/en-us/windows/win32/api/compressapi/nf-compressapi-compress
120
+ public static Compress(CompressorHandle: COMPRESSOR_HANDLE, UncompressedData: LPCVOID | NULL, UncompressedDataSize: SIZE_T, CompressedBuffer: PVOID | NULL, CompressedBufferSize: SIZE_T, CompressedDataSize: PSIZE_T): BOOL {
121
+ return Cabinet.Load('Compress')(CompressorHandle, UncompressedData, UncompressedDataSize, CompressedBuffer, CompressedBufferSize, CompressedDataSize);
122
+ }
123
+
124
+ // https://learn.microsoft.com/en-us/windows/win32/api/compressapi/nf-compressapi-createcompressor
125
+ public static CreateCompressor(Algorithm: DWORD, AllocationRoutines: PCOMPRESS_ALLOCATION_ROUTINES | NULL, CompressorHandle: PCOMPRESSOR_HANDLE): BOOL {
126
+ return Cabinet.Load('CreateCompressor')(Algorithm, AllocationRoutines, CompressorHandle);
127
+ }
128
+
129
+ // https://learn.microsoft.com/en-us/windows/win32/api/compressapi/nf-compressapi-createdecompressor
130
+ public static CreateDecompressor(Algorithm: DWORD, AllocationRoutines: PCOMPRESS_ALLOCATION_ROUTINES | NULL, DecompressorHandle: PDECOMPRESSOR_HANDLE): BOOL {
131
+ return Cabinet.Load('CreateDecompressor')(Algorithm, AllocationRoutines, DecompressorHandle);
132
+ }
133
+
134
+ // https://learn.microsoft.com/en-us/windows/win32/api/compressapi/nf-compressapi-decompress
135
+ public static Decompress(DecompressorHandle: DECOMPRESSOR_HANDLE, CompressedData: LPCVOID | NULL, CompressedDataSize: SIZE_T, UncompressedBuffer: PVOID | NULL, UncompressedBufferSize: SIZE_T, UncompressedDataSize: PSIZE_T | NULL): BOOL {
136
+ return Cabinet.Load('Decompress')(DecompressorHandle, CompressedData, CompressedDataSize, UncompressedBuffer, UncompressedBufferSize, UncompressedDataSize);
137
+ }
138
+
139
+ // https://learn.microsoft.com/en-us/windows/win32/devnotes/dllgetversion
140
+ public static DllGetVersion(pcdvi: PCABINETDLLVERSIONINFO): VOID {
141
+ return Cabinet.Load('DllGetVersion')(pcdvi);
142
+ }
143
+
144
+ // https://learn.microsoft.com/en-us/windows/win32/api/fci/nf-fci-fciaddfile
145
+ public static FCIAddFile(hfci: HFCI, pszSourceFile: LPSTR, pszFileName: LPSTR, fExecute: BOOL, pfnfcignc: PFNFCIGETNEXTCABINET, pfnfcis: PFNFCISTATUS, pfnfcigoi: PFNFCIGETOPENINFO, typeCompress: TCOMP): BOOL {
146
+ return Cabinet.Load('FCIAddFile')(hfci, pszSourceFile, pszFileName, fExecute, pfnfcignc, pfnfcis, pfnfcigoi, typeCompress);
147
+ }
148
+
149
+ // https://learn.microsoft.com/en-us/windows/win32/api/fci/nf-fci-fcicreate
150
+ public static FCICreate(
151
+ perf: PERF,
152
+ pfnfcifp: PFNFCIFILEPLACED,
153
+ pfna: PFNFCIALLOC,
154
+ pfnf: PFNFCIFREE,
155
+ pfnopen: PFNFCIOPEN,
156
+ pfnread: PFNFCIREAD,
157
+ pfnwrite: PFNFCIWRITE,
158
+ pfnclose: PFNFCICLOSE,
159
+ pfnseek: PFNFCISEEK,
160
+ pfndelete: PFNFCIDELETE,
161
+ pfnfcigtf: PFNFCIGETTEMPFILE,
162
+ pccab: PCCAB,
163
+ pv: LPVOID | NULL,
164
+ ): HFCI {
165
+ return Cabinet.Load('FCICreate')(perf, pfnfcifp, pfna, pfnf, pfnopen, pfnread, pfnwrite, pfnclose, pfnseek, pfndelete, pfnfcigtf, pccab, pv);
166
+ }
167
+
168
+ // https://learn.microsoft.com/en-us/windows/win32/api/fci/nf-fci-fcidestroy
169
+ public static FCIDestroy(hfci: HFCI): BOOL {
170
+ return Cabinet.Load('FCIDestroy')(hfci);
171
+ }
172
+
173
+ // https://learn.microsoft.com/en-us/windows/win32/api/fci/nf-fci-fciflushcabinet
174
+ public static FCIFlushCabinet(hfci: HFCI, fGetNextCab: BOOL, pfnfcignc: PFNFCIGETNEXTCABINET, pfnfcis: PFNFCISTATUS): BOOL {
175
+ return Cabinet.Load('FCIFlushCabinet')(hfci, fGetNextCab, pfnfcignc, pfnfcis);
176
+ }
177
+
178
+ // https://learn.microsoft.com/en-us/windows/win32/api/fci/nf-fci-fciflushfolder
179
+ public static FCIFlushFolder(hfci: HFCI, pfnfcignc: PFNFCIGETNEXTCABINET, pfnfcis: PFNFCISTATUS): BOOL {
180
+ return Cabinet.Load('FCIFlushFolder')(hfci, pfnfcignc, pfnfcis);
181
+ }
182
+
183
+ // https://learn.microsoft.com/en-us/windows/win32/api/fdi/nf-fdi-fdicopy
184
+ public static FDICopy(hfdi: HFDI, pszCabinet: LPSTR, pszCabPath: LPSTR, flags: INT, pfnfdin: PFNFDINOTIFY, pfnfdid: PFNFDIDECRYPT | NULL, pvUser: LPVOID | NULL): BOOL {
185
+ return Cabinet.Load('FDICopy')(hfdi, pszCabinet, pszCabPath, flags, pfnfdin, pfnfdid, pvUser);
186
+ }
187
+
188
+ // https://learn.microsoft.com/en-us/windows/win32/api/fdi/nf-fdi-fdicreate
189
+ public static FDICreate(pfnalloc: PFNALLOC, pfnfree: PFNFREE, pfnopen: PFNOPEN, pfnread: PFNREAD, pfnwrite: PFNWRITE, pfnclose: PFNCLOSE, pfnseek: PFNSEEK, cpuType: INT, perf: PERF): HFDI {
190
+ return Cabinet.Load('FDICreate')(pfnalloc, pfnfree, pfnopen, pfnread, pfnwrite, pfnclose, pfnseek, cpuType, perf);
191
+ }
192
+
193
+ // https://learn.microsoft.com/en-us/windows/win32/api/fdi/nf-fdi-fdidestroy
194
+ public static FDIDestroy(hfdi: HFDI): BOOL {
195
+ return Cabinet.Load('FDIDestroy')(hfdi);
196
+ }
197
+
198
+ // https://learn.microsoft.com/en-us/windows/win32/api/fdi/nf-fdi-fdiiscabinet
199
+ public static FDIIsCabinet(hfdi: HFDI, hf: INT_PTR, pfdici: PFDICABINETINFO): BOOL {
200
+ return Cabinet.Load('FDIIsCabinet')(hfdi, hf, pfdici);
201
+ }
202
+
203
+ // https://learn.microsoft.com/en-us/windows/win32/api/fdi/nf-fdi-fditruncatecabinet
204
+ public static FDITruncateCabinet(hfdi: HFDI, pszCabinetName: LPSTR, iFolderToDelete: USHORT): BOOL {
205
+ return Cabinet.Load('FDITruncateCabinet')(hfdi, pszCabinetName, iFolderToDelete);
206
+ }
207
+
208
+ // https://learn.microsoft.com/en-us/windows/win32/api/compressapi/nf-compressapi-querycompressorinformation
209
+ public static QueryCompressorInformation(CompressorHandle: COMPRESSOR_HANDLE, CompressInformationClass: COMPRESS_INFORMATION_CLASS, CompressInformation: PVOID, CompressInformationSize: SIZE_T): BOOL {
210
+ return Cabinet.Load('QueryCompressorInformation')(CompressorHandle, CompressInformationClass, CompressInformation, CompressInformationSize);
211
+ }
212
+
213
+ // https://learn.microsoft.com/en-us/windows/win32/api/compressapi/nf-compressapi-querydecompressorinformation
214
+ public static QueryDecompressorInformation(DecompressorHandle: DECOMPRESSOR_HANDLE, CompressInformationClass: COMPRESS_INFORMATION_CLASS, CompressInformation: PVOID, CompressInformationSize: SIZE_T): BOOL {
215
+ return Cabinet.Load('QueryDecompressorInformation')(DecompressorHandle, CompressInformationClass, CompressInformation, CompressInformationSize);
216
+ }
217
+
218
+ // https://learn.microsoft.com/en-us/windows/win32/api/compressapi/nf-compressapi-resetcompressor
219
+ public static ResetCompressor(CompressorHandle: COMPRESSOR_HANDLE): BOOL {
220
+ return Cabinet.Load('ResetCompressor')(CompressorHandle);
221
+ }
222
+
223
+ // https://learn.microsoft.com/en-us/windows/win32/api/compressapi/nf-compressapi-resetdecompressor
224
+ public static ResetDecompressor(DecompressorHandle: DECOMPRESSOR_HANDLE): BOOL {
225
+ return Cabinet.Load('ResetDecompressor')(DecompressorHandle);
226
+ }
227
+
228
+ // https://learn.microsoft.com/en-us/windows/win32/api/compressapi/nf-compressapi-setcompressorinformation
229
+ public static SetCompressorInformation(CompressorHandle: COMPRESSOR_HANDLE, CompressInformationClass: COMPRESS_INFORMATION_CLASS, CompressInformation: LPCVOID, CompressInformationSize: SIZE_T): BOOL {
230
+ return Cabinet.Load('SetCompressorInformation')(CompressorHandle, CompressInformationClass, CompressInformation, CompressInformationSize);
231
+ }
232
+
233
+ // https://learn.microsoft.com/en-us/windows/win32/api/compressapi/nf-compressapi-setdecompressorinformation
234
+ public static SetDecompressorInformation(DecompressorHandle: DECOMPRESSOR_HANDLE, CompressInformationClass: COMPRESS_INFORMATION_CLASS, CompressInformation: LPCVOID, CompressInformationSize: SIZE_T): BOOL {
235
+ return Cabinet.Load('SetDecompressorInformation')(DecompressorHandle, CompressInformationClass, CompressInformation, CompressInformationSize);
236
+ }
237
+ }
238
+
239
+ export default Cabinet;
@@ -0,0 +1,101 @@
1
+ import type { Pointer } from 'bun:ffi';
2
+
3
+ export type { BOOL, DWORD, INT, INT_PTR, LPCVOID, LPSTR, LPVOID, NULL, PVOID, SIZE_T, USHORT, VOID } from '@bun-win32/core';
4
+
5
+ export const COMPRESS_RAW = 0x2000_0000;
6
+
7
+ export enum COMPRESS_ALGORITHM {
8
+ COMPRESS_ALGORITHM_INVALID = 0,
9
+ COMPRESS_ALGORITHM_LZMS = 5,
10
+ COMPRESS_ALGORITHM_MAX = 6,
11
+ COMPRESS_ALGORITHM_MSZIP = 2,
12
+ COMPRESS_ALGORITHM_NULL = 1,
13
+ COMPRESS_ALGORITHM_XPRESS = 3,
14
+ COMPRESS_ALGORITHM_XPRESS_HUFF = 4,
15
+ }
16
+
17
+ export enum COMPRESS_INFORMATION_CLASS {
18
+ COMPRESS_INFORMATION_CLASS_BLOCK_SIZE = 1,
19
+ COMPRESS_INFORMATION_CLASS_INVALID = 0,
20
+ COMPRESS_INFORMATION_CLASS_LEVEL = 2,
21
+ }
22
+
23
+ export enum FCIERROR {
24
+ FCIERR_ALLOC_FAIL = 3,
25
+ FCIERR_BAD_COMPR_TYPE = 5,
26
+ FCIERR_CAB_FILE = 6,
27
+ FCIERR_CAB_FORMAT_LIMIT = 9,
28
+ FCIERR_MCI_FAIL = 8,
29
+ FCIERR_NONE = 0,
30
+ FCIERR_OPEN_SRC = 1,
31
+ FCIERR_READ_SRC = 2,
32
+ FCIERR_TEMP_FILE = 4,
33
+ FCIERR_USER_ABORT = 7,
34
+ }
35
+
36
+ export enum FDIERROR {
37
+ FDIERROR_ALLOC_FAIL = 5,
38
+ FDIERROR_BAD_COMPR_TYPE = 6,
39
+ FDIERROR_CABINET_NOT_FOUND = 1,
40
+ FDIERROR_CORRUPT_CABINET = 4,
41
+ FDIERROR_MDI_FAIL = 7,
42
+ FDIERROR_NONE = 0,
43
+ FDIERROR_NOT_A_CABINET = 2,
44
+ FDIERROR_RESERVE_MISMATCH = 9,
45
+ FDIERROR_TARGET_FILE = 8,
46
+ FDIERROR_UNKNOWN_CABINET_VERSION = 3,
47
+ FDIERROR_USER_ABORT = 11,
48
+ FDIERROR_WRONG_CABINET = 10,
49
+ }
50
+
51
+ export enum FDINOTIFICATIONTYPE {
52
+ fdintCABINET_INFO = 0,
53
+ fdintCLOSE_FILE_INFO = 3,
54
+ fdintCOPY_FILE = 2,
55
+ fdintENUMERATE = 5,
56
+ fdintNEXT_CABINET = 4,
57
+ fdintPARTIAL_FILE = 1,
58
+ }
59
+
60
+ export enum TCOMP_TYPE {
61
+ tcompTYPE_LZX = 3,
62
+ tcompTYPE_MSZIP = 1,
63
+ tcompTYPE_NONE = 0,
64
+ tcompTYPE_QUANTUM = 2,
65
+ }
66
+
67
+ export type COMPRESSOR_HANDLE = bigint;
68
+ export type DECOMPRESSOR_HANDLE = bigint;
69
+ export type HFCI = bigint;
70
+ export type HFDI = bigint;
71
+ export type PCABINETDLLVERSIONINFO = Pointer;
72
+ export type PCCAB = Pointer;
73
+ export type PCOMPRESS_ALLOCATION_ROUTINES = Pointer;
74
+ export type PCOMPRESSOR_HANDLE = Pointer;
75
+ export type PDECOMPRESSOR_HANDLE = Pointer;
76
+ export type PERF = Pointer;
77
+ export type PFDICABINETINFO = Pointer;
78
+ export type PFNALLOC = Pointer;
79
+ export type PFNCLOSE = Pointer;
80
+ export type PFNFCIALLOC = Pointer;
81
+ export type PFNFCICLOSE = Pointer;
82
+ export type PFNFCIDELETE = Pointer;
83
+ export type PFNFCIFILEPLACED = Pointer;
84
+ export type PFNFCIFREE = Pointer;
85
+ export type PFNFCIGETNEXTCABINET = Pointer;
86
+ export type PFNFCIGETOPENINFO = Pointer;
87
+ export type PFNFCIGETTEMPFILE = Pointer;
88
+ export type PFNFCIOPEN = Pointer;
89
+ export type PFNFCIREAD = Pointer;
90
+ export type PFNFCISEEK = Pointer;
91
+ export type PFNFCISTATUS = Pointer;
92
+ export type PFNFCIWRITE = Pointer;
93
+ export type PFNFDIDECRYPT = Pointer;
94
+ export type PFNFDINOTIFY = Pointer;
95
+ export type PFNFREE = Pointer;
96
+ export type PFNOPEN = Pointer;
97
+ export type PFNREAD = Pointer;
98
+ export type PFNSEEK = Pointer;
99
+ export type PFNWRITE = Pointer;
100
+ export type PSIZE_T = Pointer;
101
+ export type TCOMP = number;