Move base64/inflate to Support.ts
This commit is contained in:
Родитель
ad9743d895
Коммит
6f6217b544
|
@ -1,10 +1,8 @@
|
|||
"use strict";
|
||||
|
||||
import { Base64 } from "js-base64";
|
||||
|
||||
import { panic, assert } from "./Support";
|
||||
import { panic, assert, inflateBase64 } from "./Support";
|
||||
import { encodedMarkovChain } from "./EncodedMarkovChain";
|
||||
import * as pako from "pako";
|
||||
|
||||
// This must be null, not undefined, because we read it from JSON.
|
||||
export type SubTrie = number | null | Trie;
|
||||
|
@ -90,8 +88,7 @@ export function train(lines: string[], depth: number): MarkovChain {
|
|||
}
|
||||
|
||||
export function load(): MarkovChain {
|
||||
const bytes = Base64.atob(encodedMarkovChain);
|
||||
return JSON.parse(pako.inflate(bytes, { to: "string" }));
|
||||
return JSON.parse(inflateBase64(encodedMarkovChain));
|
||||
}
|
||||
|
||||
export function evaluateFull(mc: MarkovChain, word: string): [number, number[]] {
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
import { Collection, List, Set, isKeyed, isIndexed } from "immutable";
|
||||
|
||||
import { Base64 } from "js-base64";
|
||||
import * as pako from "pako";
|
||||
|
||||
export function intercalate<T>(separator: T, items: Collection<any, T>): List<T> {
|
||||
const acc: T[] = [];
|
||||
items.forEach((x: T) => {
|
||||
|
@ -173,3 +176,8 @@ export async function mapSync<K, V, U>(
|
|||
}
|
||||
return coll.map(_v => results[index++]);
|
||||
}
|
||||
|
||||
export function inflateBase64(encoded: string): string {
|
||||
const bytes = Base64.atob(encoded);
|
||||
return pako.inflate(bytes, { to: "string" });
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче