js-dos 8.1.5 → 8.1.7

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.
Files changed (140) hide show
  1. package/dist/emulators/emulators.js +2 -0
  2. package/dist/emulators/emulators.js.map +1 -0
  3. package/dist/emulators/types/build.d.ts +28 -0
  4. package/dist/emulators/types/dos/bundle/dos-bundle.d.ts +20 -0
  5. package/dist/emulators/types/dos/dosbox/ts/direct.d.ts +3 -0
  6. package/dist/emulators/types/dos/dosbox/ts/worker.d.ts +3 -0
  7. package/dist/emulators/types/emulators.d.ts +76 -0
  8. package/dist/emulators/types/http.d.ts +9 -0
  9. package/dist/emulators/types/impl/ci-impl.d.ts +29 -0
  10. package/dist/emulators/types/impl/emulators-impl.d.ts +26 -0
  11. package/dist/emulators/types/impl/modules.d.ts +38 -0
  12. package/dist/emulators/types/libzip/libzip.d.ts +16 -0
  13. package/dist/emulators/types/protocol/messages-queue.d.ts +8 -0
  14. package/dist/emulators/types/protocol/protocol.d.ts +128 -0
  15. package/dist/emulators/wdosbox-x.js +55 -0
  16. package/dist/emulators/wdosbox-x.js.symbols +8760 -0
  17. package/dist/emulators/wdosbox-x.wasm +0 -0
  18. package/dist/emulators/wdosbox.js +55 -0
  19. package/dist/emulators/wdosbox.js.symbols +3001 -0
  20. package/dist/emulators/wdosbox.wasm +0 -0
  21. package/dist/emulators/wlibzip.js +21 -0
  22. package/dist/emulators/wlibzip.js.symbols +268 -0
  23. package/dist/emulators/wlibzip.wasm +0 -0
  24. package/dist/js-dos.css +1 -0
  25. package/dist/js-dos.js +22 -0
  26. package/dist/js-dos.js.map +1 -0
  27. package/package.json +1 -1
  28. package/release.zip +0 -0
  29. package/.eslintrc.json +0 -43
  30. package/.github/workflows/build.yml +0 -51
  31. package/.gitmodules +0 -4
  32. package/index.html +0 -110
  33. package/postcss.config.cjs +0 -8
  34. package/src/app.css +0 -14
  35. package/src/base.css +0 -10
  36. package/src/components/checkbox.tsx +0 -41
  37. package/src/components/close-button.tsx +0 -17
  38. package/src/components/components.css +0 -28
  39. package/src/components/dos-option-checkbox.tsx +0 -94
  40. package/src/components/dos-option-select.tsx +0 -108
  41. package/src/components/dos-option-slider.tsx +0 -35
  42. package/src/components/error.tsx +0 -16
  43. package/src/components/loading.tsx +0 -26
  44. package/src/components/lock.tsx +0 -10
  45. package/src/components/select.tsx +0 -33
  46. package/src/components/slider.tsx +0 -69
  47. package/src/download-file.ts +0 -18
  48. package/src/frame/account-frame.tsx +0 -156
  49. package/src/frame/editor/defaults.ts +0 -419
  50. package/src/frame/editor/editor-conf-frame.tsx +0 -227
  51. package/src/frame/editor/editor-frame.css +0 -55
  52. package/src/frame/editor/editor-fs-frame.tsx +0 -314
  53. package/src/frame/fat-drives-frame.tsx +0 -199
  54. package/src/frame/frame.css +0 -119
  55. package/src/frame/frame.tsx +0 -34
  56. package/src/frame/image-rendering-frame.tsx +0 -8
  57. package/src/frame/network-frame.tsx +0 -157
  58. package/src/frame/quick-save-frame.tsx +0 -98
  59. package/src/frame/settings-frame.tsx +0 -14
  60. package/src/frame/stats-frame.tsx +0 -87
  61. package/src/host/bundle-storage.ts +0 -91
  62. package/src/host/fullscreen.ts +0 -35
  63. package/src/host/lcache.ts +0 -203
  64. package/src/host/lstorage.ts +0 -156
  65. package/src/i18n.ts +0 -185
  66. package/src/index.css +0 -7
  67. package/src/load.ts +0 -132
  68. package/src/login/login.css +0 -9
  69. package/src/login/login.tsx +0 -77
  70. package/src/main.tsx +0 -197
  71. package/src/public/types.ts +0 -45
  72. package/src/sidebar/account-button.tsx +0 -33
  73. package/src/sidebar/cloud-save-button.tsx +0 -89
  74. package/src/sidebar/diskette-icon.tsx +0 -14
  75. package/src/sidebar/fullscreen-button.tsx +0 -44
  76. package/src/sidebar/network-button.tsx +0 -39
  77. package/src/sidebar/sidebar-button.tsx +0 -244
  78. package/src/sidebar/sidebar.css +0 -47
  79. package/src/sidebar/sidebar.tsx +0 -30
  80. package/src/sockdrive/LICENSE +0 -674
  81. package/src/sockdrive/README.md +0 -45
  82. package/src/sockdrive/include/sockdrive.h +0 -23
  83. package/src/sockdrive/js/.eslintrc.json +0 -43
  84. package/src/sockdrive/js/package.json +0 -29
  85. package/src/sockdrive/js/src/fatfs/chains.js +0 -318
  86. package/src/sockdrive/js/src/fatfs/dir.js +0 -385
  87. package/src/sockdrive/js/src/fatfs/helpers.js +0 -210
  88. package/src/sockdrive/js/src/fatfs/index.js +0 -606
  89. package/src/sockdrive/js/src/fatfs/structs.js +0 -255
  90. package/src/sockdrive/js/src/fatfs/vol.js +0 -166
  91. package/src/sockdrive/js/src/sockdrive/cache.ts +0 -56
  92. package/src/sockdrive/js/src/sockdrive/drive.ts +0 -471
  93. package/src/sockdrive/js/src/sockdrive/lru.ts +0 -221
  94. package/src/sockdrive/js/src/sockdrive/types.ts +0 -14
  95. package/src/sockdrive/js/src/sockdrive-fat.d.ts +0 -64
  96. package/src/sockdrive/js/src/sockdrive-fat.ts +0 -226
  97. package/src/sockdrive/js/src/sockdrive-native.ts +0 -100
  98. package/src/sockdrive/js/src/test/test.ts +0 -289
  99. package/src/sockdrive/js/tsconfig.json +0 -11
  100. package/src/sockdrive/js/webpack.config.js +0 -68
  101. package/src/sockdrive/js/yarn.lock +0 -1808
  102. package/src/store/auth.ts +0 -115
  103. package/src/store/dos.ts +0 -305
  104. package/src/store/editor.ts +0 -61
  105. package/src/store/init.ts +0 -48
  106. package/src/store/storage.ts +0 -32
  107. package/src/store/ui.ts +0 -191
  108. package/src/store.tsx +0 -116
  109. package/src/ui.tsx +0 -140
  110. package/src/v8/changes.ts +0 -56
  111. package/src/v8/config.ts +0 -20
  112. package/src/v8/subscriptions.ts +0 -62
  113. package/src/vite-env.d.ts +0 -5
  114. package/src/window/dos/controls/keyboard.ts +0 -32
  115. package/src/window/dos/controls/keys.ts +0 -331
  116. package/src/window/dos/controls/mouse/mount.ts +0 -99
  117. package/src/window/dos/controls/mouse/mouse-locked.ts +0 -51
  118. package/src/window/dos/controls/mouse/mouse-not-locked.ts +0 -84
  119. package/src/window/dos/controls/mouse/mouse-swipe.ts +0 -57
  120. package/src/window/dos/controls/mouse/pointer.ts +0 -85
  121. package/src/window/dos/controls/mouse.ts +0 -21
  122. package/src/window/dos/dos-dhry2.tsx +0 -191
  123. package/src/window/dos/dos-runtime.tsx +0 -216
  124. package/src/window/dos/dos-window.tsx +0 -91
  125. package/src/window/dos/render/canvas.ts +0 -65
  126. package/src/window/dos/render/resize.ts +0 -31
  127. package/src/window/dos/render/webgl.ts +0 -173
  128. package/src/window/dos/sound/audio-node.ts +0 -148
  129. package/src/window/error-window.tsx +0 -9
  130. package/src/window/loading-window.tsx +0 -54
  131. package/src/window/prerun-window.tsx +0 -121
  132. package/src/window/select-window.tsx +0 -118
  133. package/src/window/window.css +0 -78
  134. package/src/window/window.tsx +0 -49
  135. package/src/ws/ws-sockdrive.ts +0 -123
  136. package/src/ws/ws-transport-layer.ts +0 -468
  137. package/tailwind.config.cjs +0 -48
  138. package/tsconfig.json +0 -32
  139. package/tsconfig.node.json +0 -9
  140. package/vite.config.ts +0 -25
@@ -1,471 +0,0 @@
1
- import { EmModule, Ptr, Stats } from "./types";
2
- import { BlockCache, Cache } from "./cache";
3
-
4
- const MAX_FRAME_SIZE = 1 * 1024 * 1024;
5
- const MEMORY_LIMIT = 64 * 1024 * 1024;
6
-
7
- interface Request {
8
- type: 1 | 2, // read | write
9
- sectors: number[],
10
- buffer: Ptr | Uint8Array,
11
- resolve: (result: number) => void,
12
- }
13
-
14
- export class Drive {
15
- module: EmModule;
16
- sectorSize: number;
17
- endpoint: string;
18
- owner: string;
19
- drive: string;
20
- token: string;
21
- stats: Stats;
22
-
23
- socket: Promise<WebSocket> = Promise.resolve(null as any);
24
- request: Request | null;
25
- pendingRequest: Request | null;
26
-
27
- aheadRange: number = 0;
28
- aheadSize: number = 0;
29
- writeBuffer: Uint8Array;
30
-
31
- maxRead: number = 0;
32
- readBuffer: Uint8Array = new Uint8Array(0);
33
- readAheadBuffer: Uint8Array = new Uint8Array(0);
34
- readAheadPos = 0;
35
- readAheadCompressed = 0;
36
- readStartedAt: number = 0;
37
- decodeBuffer: Uint8Array = new Uint8Array(0);
38
-
39
- cache: Cache | null = null;
40
- cleanup = () => {/**/};
41
-
42
- openFn = (read: boolean, write: boolean, size: number, preloadQueue: number[],
43
- aheadRange: number) => {/**/};
44
- preloadProgressFn = (restBytes: number) => {/**/};
45
- errorFn = (e: Error) => {/**/};
46
-
47
- retries: number;
48
-
49
- preloadSectors: boolean;
50
- preloadQueue: number[] = [];
51
-
52
- originReadMode: boolean;
53
- readOnly = false;
54
-
55
- public constructor(endpoint: string,
56
- owner: string,
57
- drive: string,
58
- token: string,
59
- stats: Stats,
60
- module: EmModule,
61
- preloadSectors = true,
62
- originReadMode = false) {
63
- this.sectorSize = 512;
64
- this.module = module;
65
- this.endpoint = endpoint;
66
- this.owner = owner;
67
- this.drive = drive;
68
- this.token = token;
69
- this.request = null;
70
- this.pendingRequest = null;
71
- this.writeBuffer = new Uint8Array(1 + 4 + this.sectorSize);
72
- this.stats = stats;
73
- this.retries = 3;
74
- this.preloadSectors = preloadSectors;
75
- this.originReadMode = originReadMode;
76
-
77
- this.reconnect();
78
- }
79
-
80
- public onError(errorFn: (e: Error) => void) {
81
- this.errorFn = errorFn;
82
- }
83
-
84
- public onOpen(openFn: (read: boolean, write: boolean, imageSize: number,
85
- preloadQueue: number[], aheadRange: number) => void) {
86
- this.openFn = openFn;
87
- }
88
-
89
- public onPreloadProgress(progressFn: (restBytes: number) => void) {
90
- this.preloadProgressFn = progressFn;
91
- }
92
-
93
- public reconnect(): void {
94
- this.socket = new Promise<WebSocket>((resolve, reject) => {
95
- const socket = new WebSocket(this.endpoint);
96
- socket.binaryType = "arraybuffer";
97
- const onMessage = this.onMessage.bind(this);
98
- const onOpen = () => {
99
- const onInit = (event: { data: string }) => {
100
- socket.removeEventListener("message", onInit);
101
- if (event.data.startsWith("write") || event.data.startsWith("read")) {
102
- const [mode, aheadRangeStr, sizeStr] = event.data.split(",");
103
- const aheadRange = Number.parseInt(aheadRangeStr);
104
- this.aheadRange = aheadRange;
105
- this.aheadSize = aheadRange * this.sectorSize;
106
- this.maxRead = Math.floor(MAX_FRAME_SIZE / this.aheadSize);
107
-
108
- const decodeBufferSize = this.aheadSize * this.maxRead;
109
- this.readBuffer = new Uint8Array(1 + 4 + this.maxRead * 4);
110
- this.readAheadBuffer = new Uint8Array(decodeBufferSize);
111
- this.decodeBuffer = new Uint8Array(decodeBufferSize);
112
- this.cache = new BlockCache(this.sectorSize, aheadRange, MEMORY_LIMIT);
113
-
114
- let preloadLength = 0;
115
- let preloadPos = 0;
116
- let preload: Uint8Array = new Uint8Array(0);
117
- const onPreloadMessage = (event: { data: ArrayBuffer }) => {
118
- let data = new Uint8Array(event.data);
119
- if (preloadLength === 0) {
120
- preloadLength = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24);
121
- preload = new Uint8Array(preloadLength - 4);
122
- data = data.slice(4);
123
- }
124
-
125
- if (preloadPos < preloadLength) {
126
- preload.set(data, preloadPos);
127
- preloadPos += data.length;
128
- }
129
-
130
- if (preloadPos > preload.length) {
131
- const error = new Error("Preload buffer is bigger then expected");
132
- this.errorFn(error);
133
- reject(error);
134
- } else if (preloadPos == preload.length) {
135
- this.preloadQueue = [];
136
- if (this.preloadSectors) {
137
- for (let i = 0; i < preload.length; i += 4) {
138
- this.preloadQueue.push(preload[i] + (preload[i + 1] << 8) +
139
- (preload[i + 2] << 16) + (preload[i + 3] << 24));
140
- }
141
- }
142
- socket.removeEventListener("message", onPreloadMessage);
143
- socket.addEventListener("message", onMessage);
144
- this.readOnly = mode !== "write";
145
- this.openFn(true, !this.readOnly,
146
- (Number.parseInt(sizeStr) ?? 2 * 1024 * 1024) * 1024,
147
- this.preloadQueue,
148
- aheadRange);
149
- resolve(socket);
150
-
151
- if (this.preloadQueue.length > 0) {
152
- if (this.preloadQueue.length * this.aheadSize > MEMORY_LIMIT) {
153
- console.log("WARN! preloadQueue size is bigger then allowed",
154
- this.preloadQueue.length * this.aheadSize / 1024 / 1024, ">",
155
- MEMORY_LIMIT / 1024 / 1024);
156
- this.preloadQueue = this.preloadQueue
157
- .slice(0, Math.floor(MEMORY_LIMIT / this.aheadSize));
158
- }
159
- this.request = this.makeReadRequest(this.preloadQueue.shift()!);
160
- this.executeRequest(this.request);
161
- }
162
- }
163
- };
164
- socket.addEventListener("message", onPreloadMessage);
165
- } else {
166
- const error = new Error(event.data ?? "Unable to establish connection");
167
- this.errorFn(error);
168
- reject(error);
169
- }
170
- };
171
- socket.addEventListener("message", onInit);
172
- socket.send(this.owner + "&" + this.drive + "&" + this.token);
173
- };
174
- const onError = (e: Event) => {
175
- console.error("Network error", e, "will reconnect");
176
- cleanup();
177
- socket.close();
178
- this.retries--;
179
- if (this.retries === 0) {
180
- const error = new Error("Network problem");
181
- this.errorFn(error);
182
- reject(error);
183
- } else {
184
- setTimeout(this.reconnect.bind(this), 300);
185
- }
186
- };
187
- socket.addEventListener("error", onError);
188
- socket.addEventListener("open", onOpen);
189
- const cleanup = function() {
190
- socket.removeEventListener("message", onMessage);
191
- socket.removeEventListener("open", onOpen);
192
- socket.removeEventListener("error", onError);
193
- };
194
- this.cleanup = cleanup;
195
- });
196
-
197
- if (this.request !== null) {
198
- this.executeRequest(this.request);
199
- }
200
- }
201
-
202
- private makeReadRequest(sector: number, buffer: number = -1, resolve: (res: number) => void = () => { }): Request {
203
- const sectors: number[] = [sector];
204
- if (this.preloadQueue.length > 0) {
205
- this.preloadProgressFn(this.preloadQueue.length * this.aheadSize);
206
- while (this.preloadQueue.length > 0 && sectors.length < this.maxRead) {
207
- const preload = this.preloadQueue.shift()!;
208
- if (preload !== sector) {
209
- sectors.push(preload);
210
- }
211
- }
212
- for (let i = 0; i < this.preloadQueue.length; ++i) {
213
- if (this.preloadQueue[i] == sector) {
214
- this.preloadQueue.splice(i, 1);
215
- break;
216
- }
217
- }
218
- }
219
- return {
220
- type: 1,
221
- sectors,
222
- buffer,
223
- resolve,
224
- };
225
- }
226
-
227
- public read(sector: number, buffer: Ptr, sync: boolean): Promise<number> | number {
228
- const cached = this.cache!.read(sector, this.originReadMode);
229
- if (cached !== null) {
230
- this.stats.cacheHit++;
231
- this.module.HEAPU8.set(cached, buffer);
232
- return sync ? 0 : Promise.resolve(0);
233
- } else if (sync) {
234
- return 255;
235
- } else {
236
- return new Promise<number>((resolve) => {
237
- this.stats.cacheMiss++;
238
-
239
- const request: Request = this.makeReadRequest(sector, buffer, resolve);
240
- if (this.request !== null) {
241
- if (this.pendingRequest === null) {
242
- this.pendingRequest = request;
243
- } else {
244
- console.error("New read request while old one is still processed");
245
- resolve(3);
246
- }
247
- } else {
248
- this.request = request;
249
- this.executeRequest(this.request);
250
- }
251
- });
252
- }
253
- }
254
-
255
- public write(sector: number, buffer: Ptr): number {
256
- const request: Request = {
257
- type: 2,
258
- sectors: [sector],
259
- buffer: this.module.HEAPU8.slice(buffer, buffer + this.sectorSize),
260
- resolve: () => {/**/},
261
- };
262
- this.cache!.write(sector, request.buffer as Uint8Array);
263
- this.executeRequest(request);
264
- return 0;
265
- }
266
-
267
- public async close() {
268
- const socket = await this.socket;
269
- await new Promise<void>((resolve) => {
270
- const intervalId = setInterval(() => {
271
- if (socket.bufferedAmount === 0) {
272
- clearInterval(intervalId);
273
- resolve();
274
- }
275
- }, 32);
276
- });
277
- this.cleanup();
278
- socket.close();
279
- }
280
-
281
- private executeRequest(request: Request) {
282
- this.socket.then((socket) => {
283
- if (request.type === 1) {
284
- const { sectors } = request;
285
- this.readStartedAt = Date.now();
286
- this.readAheadPos = 0;
287
- this.readAheadCompressed = 0;
288
- this.readBuffer[0] = 1; // read
289
- this.readBuffer[1] = sectors.length & 0xFF;
290
- this.readBuffer[2] = (sectors.length >> 8) & 0xFF;
291
- this.readBuffer[3] = (sectors.length >> 16) & 0xFF;
292
- this.readBuffer[4] = (sectors.length >> 24) & 0xFF;
293
-
294
- for (let i = 0; i < sectors.length; ++i) {
295
- const origin = this.cache!.getOrigin(sectors[i]);
296
-
297
- if (i > 0 && origin !== sectors[i]) {
298
- console.error("Assertion failed orign should equal to sector", origin, sectors[i]);
299
- request.resolve(5);
300
- return;
301
- }
302
-
303
- this.readBuffer[5 + i * 4] = origin & 0xFF;
304
- this.readBuffer[5 + i * 4 + 1] = (origin >> 8) & 0xFF;
305
- this.readBuffer[5 + i * 4 + 2] = (origin >> 16) & 0xFF;
306
- this.readBuffer[5 + i * 4 + 3] = (origin >> 24) & 0xFF;
307
- }
308
- socket.send(this.readBuffer.slice(0, sectors.length * 4 + 5).buffer);
309
- } else if (this.readOnly) {
310
- request.resolve(0);
311
- } else {
312
- const { sectors, buffer, resolve } = request;
313
- this.stats.write += this.sectorSize;
314
- this.writeBuffer[0] = 2; // write
315
- this.writeBuffer[1] = sectors[0] & 0xFF;
316
- this.writeBuffer[2] = (sectors[0] >> 8) & 0xFF;
317
- this.writeBuffer[3] = (sectors[0] >> 16) & 0xFF;
318
- this.writeBuffer[4] = (sectors[0] >> 24) & 0xFF;
319
- // TBD: maybe do not copy and send just slice ???
320
- this.writeBuffer.set(buffer as Uint8Array, 5);
321
- socket.send(this.writeBuffer.buffer);
322
- resolve(0);
323
- }
324
- });
325
- }
326
-
327
- public onMessage(event: { data: ArrayBuffer }) {
328
- if (this.request === null) {
329
- console.error("Received message without request");
330
- this.reconnect();
331
- } else if (this.request.type === 2) {
332
- console.error("Received read payload while write request");
333
- this.reconnect();
334
- } else if (event.data instanceof ArrayBuffer) {
335
- let data = new Uint8Array(event.data);
336
- if (this.readAheadCompressed === 0) {
337
- this.readAheadCompressed = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24);
338
- data = data.slice(4);
339
- }
340
-
341
- const { sectors, buffer, resolve } = this.request;
342
- const restLength = this.readAheadCompressed - this.readAheadPos;
343
- if (data.byteLength > restLength || restLength < 0) {
344
- console.error("wrong read payload length " + data.byteLength + " instead of " + restLength);
345
- resolve(3);
346
- } else {
347
- this.readAheadBuffer.set(data, this.readAheadPos);
348
- this.readAheadPos += data.byteLength;
349
- const expectedSize = this.aheadSize * sectors.length;
350
-
351
- if (this.readAheadPos == this.readAheadCompressed) {
352
- let decodeResult = expectedSize;
353
- if (this.readAheadCompressed < expectedSize) {
354
- const result = decodeLz4(this.readAheadBuffer, this.decodeBuffer, 0, this.readAheadCompressed);
355
- if (result < 0) {
356
- decodeResult = result;
357
- } else {
358
- this.readAheadBuffer.set(this.decodeBuffer.slice(0, expectedSize), 0);
359
- }
360
- }
361
-
362
- if (decodeResult != expectedSize) {
363
- console.error("wrong decode result " + decodeResult + " should be " + expectedSize);
364
- resolve(4);
365
- } else {
366
- for (let i = 0; i < sectors.length; ++i) {
367
- const aheadOffset = i * this.aheadSize;
368
- const sector = sectors[i];
369
- const origin = this.cache!.getOrigin(sector);
370
- this.cache!.create(origin,
371
- this.readAheadBuffer.slice(aheadOffset, aheadOffset + this.aheadSize));
372
- if (i == 0 && buffer as number >= 0) {
373
- if (this.originReadMode && sector !== origin) {
374
- throw new Error("Sector must be one of origins in originReadMode");
375
- }
376
- const offset = sector - origin;
377
- // aheadOffset is zero
378
- const from = offset * this.sectorSize;
379
- this.module.HEAPU8.set(this.readAheadBuffer
380
- .slice(from, from + (this.originReadMode ? this.aheadRange : 1) * this.sectorSize),
381
- buffer as number);
382
- }
383
- }
384
-
385
- this.stats.cacheUsed = this.cache!.memUsed();
386
- this.stats.read += this.readAheadCompressed;
387
- this.stats.readTotalTime += Date.now() - this.readStartedAt;
388
- this.request = null;
389
- resolve(0);
390
-
391
- if (this.pendingRequest !== null) {
392
- this.request = this.pendingRequest;
393
- this.pendingRequest = null;
394
- this.executeRequest(this.request);
395
- } else if (this.preloadQueue.length > 0) {
396
- this.request = this.makeReadRequest(this.preloadQueue.shift()!);
397
- this.executeRequest(this.request);
398
- }
399
- }
400
- }
401
- }
402
- } else {
403
- console.error("Received non arraybuffer data");
404
- this.reconnect();
405
- }
406
- }
407
- }
408
-
409
- /**
410
- * Decode a block. Assumptions: input contains all sequences of a
411
- * chunk, output is large enough to receive the decoded data.
412
- * If the output buffer is too small, an error will be thrown.
413
- * If the returned value is negative, an error occured at the returned offset.
414
- *
415
- * @param {ArrayBufferView} input input data
416
- * @param {ArrayBufferView} output output data
417
- * @param {number=} sIdx
418
- * @param {number=} eIdx
419
- * @return {number} number of decoded bytes
420
- * @private
421
- */
422
- function decodeLz4(input: Uint8Array, output: Uint8Array, sIdx: number, eIdx: number) {
423
- sIdx = sIdx || 0;
424
- eIdx = eIdx || (input.length - sIdx);
425
- // Process each sequence in the incoming data
426
- let i; let n; let j;
427
- for (i = sIdx, n = eIdx, j = 0; i < n;) {
428
- const token = input[i++];
429
-
430
- // Literals
431
- let literalsLength = (token >> 4);
432
- if (literalsLength > 0) {
433
- // length of literals
434
- let l = literalsLength + 240;
435
- while (l === 255) {
436
- l = input[i++];
437
- literalsLength += l;
438
- }
439
-
440
- // Copy the literals
441
- const end = i + literalsLength;
442
- while (i < end) output[j++] = input[i++];
443
-
444
- // End of buffer?
445
- if (i === n) return j;
446
- }
447
-
448
- // Match copy
449
- // 2 bytes offset (little endian)
450
- const offset = input[i++] | (input[i++] << 8);
451
-
452
- // XXX 0 is an invalid offset value
453
- if (offset === 0) return j;
454
- if (offset > j) return -(i - 2);
455
-
456
- // length of match copy
457
- let matchLength = (token & 0xf);
458
- let l = matchLength + 240;
459
- while (l === 255) {
460
- l = input[i++];
461
- matchLength += l;
462
- }
463
-
464
- // Copy the match
465
- let pos = j - offset; // position of the match copy in the current output
466
- const end = j + matchLength + 4; // minmatch = 4
467
- while (j < end) output[j++] = output[pos++];
468
- }
469
-
470
- return j;
471
- };
@@ -1,221 +0,0 @@
1
- /* eslint-disable */
2
-
3
- // This code is from https://github.com/rsms/js-lru
4
-
5
- /**
6
- * A doubly linked list-based Least Recently Used (LRU) cache. Will keep most
7
- * recently used items while discarding least recently used items when its limit
8
- * is reached.
9
- *
10
- * Licensed under MIT. Copyright (c) 2010 Rasmus Andersson <http://hunch.se/>
11
- * See README.md for details.
12
- *
13
- * Illustration of the design:
14
- *
15
- * entry entry entry entry
16
- * ______ ______ ______ ______
17
- * | head |.newer => | |.newer => | |.newer => | tail |
18
- * | A | | B | | C | | D |
19
- * |______| <= older.|______| <= older.|______| <= older.|______|
20
- *
21
- * removed <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- added
22
- */
23
- const NEWER = Symbol("newer");
24
- const OLDER = Symbol("older");
25
-
26
- export class LRUMap {
27
- size: number;
28
- limit: number;
29
- newest: any;
30
- oldest: any;
31
- _keymap: Map<any, any>;
32
-
33
- constructor(limit: number, entries?: any) {
34
- if (typeof limit !== "number") {
35
- // called as (entries)
36
- entries = limit;
37
- limit = 0;
38
- }
39
-
40
- this.size = 0;
41
- this.limit = limit;
42
- this.oldest = this.newest = undefined;
43
- this._keymap = new Map();
44
-
45
- if (entries) {
46
- this.assign(entries);
47
- if (limit < 1) {
48
- this.limit = this.size;
49
- }
50
- }
51
- }
52
-
53
- _markEntryAsUsed(entry: any) {
54
- if (entry === this.newest) {
55
- // Already the most recenlty used entry, so no need to update the list
56
- return;
57
- }
58
- // HEAD--------------TAIL
59
- // <.older .newer>
60
- // <--- add direction --
61
- // A B C <D> E
62
- if (entry[NEWER]) {
63
- if (entry === this.oldest) {
64
- this.oldest = entry[NEWER];
65
- }
66
- entry[NEWER][OLDER] = entry[OLDER]; // C <-- E.
67
- }
68
- if (entry[OLDER]) {
69
- entry[OLDER][NEWER] = entry[NEWER]; // C. --> E
70
- }
71
- entry[NEWER] = undefined; // D --x
72
- entry[OLDER] = this.newest; // D. --> E
73
- if (this.newest) {
74
- this.newest[NEWER] = entry; // E. <-- D
75
- }
76
- this.newest = entry;
77
- }
78
-
79
- assign(entries: any) {
80
- let entry; let limit = this.limit || Number.MAX_VALUE;
81
- this._keymap.clear();
82
- const it = entries[Symbol.iterator]();
83
- for (let itv = it.next(); !itv.done; itv = it.next()) {
84
- const e = new (Entry as any)(itv.value[0], itv.value[1]);
85
- this._keymap.set(e.key, e);
86
- if (!entry) {
87
- this.oldest = e;
88
- } else {
89
- entry[NEWER] = e;
90
- e[OLDER] = entry;
91
- }
92
- entry = e;
93
- if (limit-- == 0) {
94
- throw new Error("overflow");
95
- }
96
- }
97
- this.newest = entry;
98
- this.size = this._keymap.size;
99
- }
100
-
101
- get(key: any) {
102
- // First, find our cache entry
103
- const entry = this._keymap.get(key);
104
- if (!entry) return; // Not cached. Sorry.
105
- // As <key> was found in the cache, register it as being requested recently
106
- this._markEntryAsUsed(entry);
107
- return entry.value;
108
- }
109
-
110
- set(key: any, value: any) {
111
- let entry = this._keymap.get(key);
112
-
113
- if (entry) {
114
- // update existing
115
- entry.value = value;
116
- this._markEntryAsUsed(entry);
117
- return this;
118
- }
119
-
120
- // new entry
121
- this._keymap.set(key, (entry = new (Entry as any)(key, value)));
122
-
123
- if (this.newest) {
124
- // link previous tail to the new tail (entry)
125
- this.newest[NEWER] = entry;
126
- entry[OLDER] = this.newest;
127
- } else {
128
- // we're first in -- yay
129
- this.oldest = entry;
130
- }
131
-
132
- // add new entry to the end of the linked list -- it's now the freshest entry.
133
- this.newest = entry;
134
- ++this.size;
135
- if (this.size > this.limit) {
136
- // we hit the limit -- remove the head
137
- this.shift();
138
- }
139
-
140
- return this;
141
- }
142
-
143
- shift() {
144
- // todo: handle special case when limit == 1
145
- const entry = this.oldest;
146
- if (entry) {
147
- if (this.oldest[NEWER]) {
148
- // advance the list
149
- this.oldest = this.oldest[NEWER];
150
- this.oldest[OLDER] = undefined;
151
- } else {
152
- // the cache is exhausted
153
- this.oldest = undefined;
154
- this.newest = undefined;
155
- }
156
- // Remove last strong reference to <entry> and remove links from the purged
157
- // entry being returned:
158
- entry[NEWER] = entry[OLDER] = undefined;
159
- this._keymap.delete(entry.key);
160
- --this.size;
161
- return [entry.key, entry.value];
162
- }
163
- }
164
- }
165
-
166
- function Entry(this: any, key: any, value: any) {
167
- this.key = key;
168
- this.value = value;
169
- this[NEWER] = undefined;
170
- this[OLDER] = undefined;
171
- }
172
-
173
-
174
- function EntryIterator(this: any, oldestEntry: any) {
175
- this.entry = oldestEntry;
176
- }
177
- EntryIterator.prototype[Symbol.iterator] = function () {
178
- return this;
179
- };
180
- EntryIterator.prototype.next = function () {
181
- const ent = this.entry;
182
- if (ent) {
183
- this.entry = ent[NEWER];
184
- return { done: false, value: [ent.key, ent.value] };
185
- } else {
186
- return { done: true, value: undefined };
187
- }
188
- };
189
-
190
-
191
- function KeyIterator(this: any, oldestEntry: any) {
192
- this.entry = oldestEntry;
193
- }
194
- KeyIterator.prototype[Symbol.iterator] = function () {
195
- return this;
196
- };
197
- KeyIterator.prototype.next = function () {
198
- const ent = this.entry;
199
- if (ent) {
200
- this.entry = ent[NEWER];
201
- return { done: false, value: ent.key };
202
- } else {
203
- return { done: true, value: undefined };
204
- }
205
- };
206
-
207
- function ValueIterator(this: any, oldestEntry: any) {
208
- this.entry = oldestEntry;
209
- }
210
- ValueIterator.prototype[Symbol.iterator] = function () {
211
- return this;
212
- };
213
- ValueIterator.prototype.next = function () {
214
- const ent = this.entry;
215
- if (ent) {
216
- this.entry = ent[NEWER];
217
- return { done: false, value: ent.value };
218
- } else {
219
- return { done: true, value: undefined };
220
- }
221
- };
@@ -1,14 +0,0 @@
1
- export type Handle = number;
2
- export type Ptr = number;
3
- export interface Stats {
4
- read: number,
5
- write: number,
6
- readTotalTime: number,
7
- cacheHit: number,
8
- cacheMiss: number,
9
- cacheUsed: number,
10
- };
11
-
12
- export interface EmModule {
13
- HEAPU8: Uint8Array,
14
- };