Skip to content

Commit

Permalink
LZMA workaround as per classroom
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-matt-hillsdon committed Mar 12, 2024
1 parent 59a2d56 commit 6d08aa6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/fs/lzma.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
declare module "lzma/src/lzma-d-min";
declare module "lzma/src/lzma-d";
14 changes: 10 additions & 4 deletions src/fs/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
*/
import { toByteArray } from "base64-js";

import lzma from "lzma/src/lzma-d";

// LZMA isn't a proper module.
// When bundled it assigns to window. At dev time it works via the above import.
const LZMA =
typeof window !== "undefined" && (window as any).LZMA
? (window as any).LZMA
: lzma.LZMA;

// There are other fields that we don't use.
export interface Migration {
meta: {
Expand Down Expand Up @@ -34,10 +43,7 @@ export const parseMigrationFromUrl = (
try {
if (urlPart) {
const bytes = toByteArray(urlPart);
const json = JSON.parse(
// FIXME, reinstate decompression with a working module.
/*LZMA.decompress(*/ new TextDecoder().decode(bytes) /*)*/
);
const json = JSON.parse(LZMA.decompress(bytes));
if (isMigration(json)) {
let postMigrationUrl = parts[0];
// This was previously stripped off by the versioner but for now do it ourselves:
Expand Down

0 comments on commit 6d08aa6

Please sign in to comment.