Skip to content
Merged
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
9 changes: 9 additions & 0 deletions cli/src/logout.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/********************************************************************************
* Copyright (c) 2024 Precies. Software and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import { openDefaultStore } from "./store";

export default async function logout(namespaceName: string) {
Expand Down
9 changes: 9 additions & 0 deletions cli/src/store.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/********************************************************************************
* Copyright (c) 2024 Precies. Software and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import * as fs from 'fs';
import * as path from 'path';
import { homedir } from 'os';
Expand Down
45 changes: 30 additions & 15 deletions cli/src/zip.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/********************************************************************************
* Copyright (c) 2024 Precies. Software and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import { Entry, open, ZipFile } from 'yauzl';
import { Readable } from 'stream';
import { Manifest } from './util';
Expand All @@ -11,32 +20,38 @@ async function bufferStream(stream: Readable): Promise<Buffer> {
});
}

export async function readZip(packagePath: string, filter: (name: string) => boolean): Promise<Map<string, Buffer>> {
const zipfile = await new Promise<ZipFile>((resolve, reject) =>
async function openZip(packagePath: string) {
return new Promise<ZipFile>((resolve, reject) =>
open(packagePath, { lazyEntries: true }, (err: Error | null, zipfile: ZipFile) => (err ? reject(err) : resolve(zipfile)))
);
}

async function readZip(packagePath: string, filter: (name: string) => boolean): Promise<Map<string, Buffer>> {
const zipfile = await openZip(packagePath);

return await new Promise((resolve, reject) => {
const result = new Map<string, Buffer>();

zipfile.once('close', () => resolve(result));

zipfile.readEntry();
zipfile.on('streamEntry', (entry: Entry) => {
zipfile.openReadStream(entry, (err: Error | null, stream: Readable) => {
if (err) {
zipfile.close();
return reject(err);
}

bufferStream(stream).then(buffer => {
const name = entry.fileName.toLowerCase();
result.set(name, buffer);
zipfile.readEntry();
});
});
});
zipfile.on('entry', (entry: Entry) => {
const name = entry.fileName.toLowerCase();

if (filter(name)) {
zipfile.openReadStream(entry, (err: Error | null, stream: Readable) => {
if (err) {
zipfile.close();
return reject(err);
}

bufferStream(stream).then(buffer => {
result.set(name, buffer);
zipfile.readEntry();
});
});
zipfile.emit('streamEntry', entry);
} else {
zipfile.readEntry();
}
Expand Down