Skip to content

Commit

Permalink
return compressed size for each file
Browse files Browse the repository at this point in the history
  • Loading branch information
leyhline committed Jun 24, 2023
1 parent 29d6fea commit 780b282
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/mecab-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,16 @@ async function collectFiles(
while (true) {
const { done, value } = await reader.read();
if (done) break;
const [file, compressedSize] = value;
const message: MecabNetwork | MecabCache = {
id: 0,
type: type,
name: value.name,
size: value.size,
name: file.name,
size: compressedSize,
total: contentLength,
};
postMessage(message);
files.push(value);
files.push(file);
}
if (files.length === 0) {
throw new Error("No files extracted");
Expand Down
14 changes: 10 additions & 4 deletions src/unzip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ declare class DecompressionStream extends TransformStream<

export async function unzipDictionary(
response: Response
): Promise<[ReadableStream<File>, number | null]> {
): Promise<[ReadableStream<[File, number]>, number | null]> {
if (!testDecompressionStreamSupport()) {
throw new Error(
"Cannot unzip dictionary. DecompressionStream API is not supported by this browser."
Expand Down Expand Up @@ -37,7 +37,7 @@ function testDecompressionStreamSupport(): boolean {

async function unzip(
stream: ReadableStream<Uint8Array>
): Promise<ReadableStream<File>> {
): Promise<ReadableStream<[File, number]>> {
return new ReadableStream({
pull: async (controller) => {
const reader = new ZipReader(stream);
Expand All @@ -50,10 +50,16 @@ async function unzip(
}
if (header.compressionMethod === 8) {
const data = await reader.decompress(header.compressedSize);
controller.enqueue(new File([data], header.fileName));
controller.enqueue([
new File([data], header.fileName),
header.compressedSize,
]);
} else {
const data = await reader.read(header.compressedSize);
controller.enqueue(new File([data], header.fileName));
controller.enqueue([
new File([data], header.fileName),
header.compressedSize,
]);
}
}
},
Expand Down

0 comments on commit 780b282

Please sign in to comment.