Skip to content

Commit

Permalink
refactor: impl zip task
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Jan 5, 2022
1 parent e20d885 commit 2f498a2
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/main/util/zip.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { path7za } from '7zip-bin'
import { unpack } from '7zip-min'
import { BaseTask, CancelledError } from '@xmcl/task'
import { AbortableTask, BaseTask, CancelledError } from '@xmcl/task'
import { spawn } from 'child_process'
import { createWriteStream, promises } from 'fs'
import { ensureFile, stat } from 'fs-extra'
Expand All @@ -14,7 +14,8 @@ import { pipeline } from './fs'
export const gunzip: (data: Buffer) => Promise<Buffer> = promisify(_gunzip)
export const gzip: (data: Buffer) => Promise<Buffer> = promisify(_gzip)

export class ZipTask extends BaseTask<void> {
export class ZipTask extends AbortableTask<void> {

private writeStream: Writable | undefined

constructor(readonly destination: string, readonly zipFile: ZipFile = new ZipFile()) {
Expand Down Expand Up @@ -75,11 +76,12 @@ export class ZipTask extends BaseTask<void> {
})
}
await promise
this.writeStream.end
}

protected async validate(): Promise<void> { }

protected shouldTolerant(e: any): boolean { return false }
protected isAbortedError(e: any): boolean {
throw false
}

protected async abort(isCancelled: boolean): Promise<void> {
if (isCancelled) {
Expand All @@ -89,19 +91,6 @@ export class ZipTask extends BaseTask<void> {
this.zipFile.outputStream.pause()
}
}

protected runTask(): Promise<void> {
throw new Error('Method not implemented.')
}
protected cancelTask(): Promise<void> {
throw new Error('Method not implemented.')
}
protected pauseTask(): Promise<void> {
throw new Error('Method not implemented.')
}
protected resumeTask(): Promise<void> {
throw new Error('Method not implemented.')
}
}

export function unpack7z(archivePath: string, destinationDirectory: string) {
Expand Down

0 comments on commit 2f498a2

Please sign in to comment.