-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
30 lines (22 loc) · 1.19 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { MFSWriter } from "./writer";
import { MFSReader } from "./reader";
import { CompressionType } from "./types";
import { read, writeFileSync } from 'fs';
const writer = new MFSWriter();
writer.setCustomDataCompressionType(CompressionType.None);
//writer.addExternalFile('baller.txt', { filename: 'baller.txt', offset: 0, length: 26 }, 'This is a file about a baller!');
writer.addFileFromPath("image.png", "testImg.png", "A cool test image!", CompressionType.Brotli);
//writer.addFile('test.txt', encoder.encode("The quick brown fox jumps over the lazy dog, but was he fast enough?"), '', CompressionType.Brotli);
//writer.addFile('test2.txt', encoder.encode("The quick brown fox jumps over the lazy dog, but he fast enough!"), '', CompressionType.Gzip);
(async () => {
const data = await writer.export();
// save to file
writeFileSync('test.mfs', Buffer.from(data));
//MFSReader.from('./test.mfs');
const reader = new MFSReader(new Uint8Array(data))
await reader.readFile();
let file = reader.files.find(f => f.fileName == 'image.png');
console.log(file?.customData)
if (!file) return;
writeFileSync('test.png', Buffer.from((await file?.read()).buffer));
})()