Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add github:artifact resource that unzips the doubly zipped files #1799

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function streamCentralDirectoryEntries(source: BytesSource) {
* @param source
* @returns
*/
async function streamCentralDirectoryBytes(source: BytesSource) {
export async function streamCentralDirectoryBytes(source: BytesSource) {
const chunkSize = CENTRAL_DIRECTORY_END_SCAN_CHUNK_SIZE;
let centralDirectory: Uint8Array = new Uint8Array();

Expand Down
37 changes: 24 additions & 13 deletions packages/php-wasm/stream-compression/src/zip/decode-zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
} from './types';
import { filterStream } from '../utils/filter-stream';
import { collectBytes } from '../utils/collect-bytes';
import { limitBytes } from '../utils/limit-bytes';

Check failure on line 22 in packages/php-wasm/stream-compression/src/zip/decode-zip.ts

View workflow job for this annotation

GitHub Actions / Lint and typecheck

'limitBytes' is defined but never used
import { concatBytes } from '../utils/concat-bytes';

Check failure on line 23 in packages/php-wasm/stream-compression/src/zip/decode-zip.ts

View workflow job for this annotation

GitHub Actions / Lint and typecheck

'concatBytes' is defined but never used
import { prependBytes } from '../utils/prepend-bytes';

Check failure on line 24 in packages/php-wasm/stream-compression/src/zip/decode-zip.ts

View workflow job for this annotation

GitHub Actions / Lint and typecheck

'prependBytes' is defined but never used
import { appendBytes } from '../utils/append-bytes';

Check failure on line 25 in packages/php-wasm/stream-compression/src/zip/decode-zip.ts

View workflow job for this annotation

GitHub Actions / Lint and typecheck

'appendBytes' is defined but never used

/**
* Unzips a stream of zip file bytes.
Expand All @@ -33,7 +33,9 @@
*/
export function decodeZip(
stream: ReadableStream<Uint8Array>,
predicate?: () => boolean
predicate: (
dirEntry: CentralDirectoryEntry | FileEntry
) => boolean = DEFAULT_PREDICATE
) {
return streamZippedFileEntries(stream, predicate).pipeThrough(
new TransformStream<FileEntry, File>({
Expand Down Expand Up @@ -143,6 +145,7 @@
}
}
const data = new DataView((await collectBytes(stream, 26))!.buffer);
console.log(data);

Check warning on line 148 in packages/php-wasm/stream-compression/src/zip/decode-zip.ts

View workflow job for this annotation

GitHub Actions / Lint and typecheck

Unexpected console statement
const pathLength = data.getUint16(22, true);
const extraLength = data.getUint16(24, true);
const entry: Partial<FileEntry> = {
Expand All @@ -168,9 +171,15 @@
// eagerly. Ensure the next iteration exhausts
// the last body stream before moving on.

let bodyStream = limitBytes(stream, entry['compressedSize']!);
console.log('entry', { entry });

Check warning on line 174 in packages/php-wasm/stream-compression/src/zip/decode-zip.ts

View workflow job for this annotation

GitHub Actions / Lint and typecheck

Unexpected console statement
console.log('compressedSize', entry['compressedSize']!);

Check warning on line 175 in packages/php-wasm/stream-compression/src/zip/decode-zip.ts

View workflow job for this annotation

GitHub Actions / Lint and typecheck

Unexpected console statement
let bodyStream = stream; // limitBytes(stream, entry['compressedSize']!);

if (entry['compressionMethod'] === COMPRESSION_DEFLATE) {
bodyStream = bodyStream.pipeThrough(
new DecompressionStream('deflate-raw')
);

/**
* We want to write raw deflate-compressed bytes into our
* final ZIP file. CompressionStream supports "deflate-raw"
Expand All @@ -193,23 +202,25 @@
* - 4 bytes for CRC32 of the uncompressed data
* - 4 bytes for ISIZE (uncompressed size modulo 2^32)
*/
const header = new Uint8Array(10);
header.set([0x1f, 0x8b, 0x08]);
// const header = new Uint8Array(10);
// header.set([0x1f, 0x8b, 0x08]);

const footer = new Uint8Array(8);
const footerView = new DataView(footer.buffer);
footerView.setUint32(0, entry.crc!, true);
footerView.setUint32(4, entry.uncompressedSize! % 2 ** 32, true);
bodyStream = bodyStream
.pipeThrough(prependBytes(header))
.pipeThrough(appendBytes(footer))
.pipeThrough(new DecompressionStream('gzip'));
// const footer = new Uint8Array(8);
// const footerView = new DataView(footer.buffer);
// footerView.setUint32(0, entry.crc!, true);
// footerView.setUint32(4, entry.uncompressedSize! % 2 ** 32, true);
// bodyStream = bodyStream
// .pipeThrough(prependBytes(header))
// .pipeThrough(appendBytes(footer))
// .pipeThrough(new DecompressionStream('gzip'));
}
entry['bytes'] = await bodyStream
.pipeThrough(concatBytes(entry['uncompressedSize']))
// .pipeThrough(concatBytes(entry['uncompressedSize']))
.getReader()
.read()
.then(({ value }) => value!);
console.log({ entry });

Check warning on line 222 in packages/php-wasm/stream-compression/src/zip/decode-zip.ts

View workflow job for this annotation

GitHub Actions / Lint and typecheck

Unexpected console statement
console.log(new TextDecoder().decode(entry.path!));

Check warning on line 223 in packages/php-wasm/stream-compression/src/zip/decode-zip.ts

View workflow job for this annotation

GitHub Actions / Lint and typecheck

Unexpected console statement
return entry as FileEntry;
}

Expand Down
Loading
Loading