7zip-bin-wrapper 中文文档教程

发布于 3年前 浏览 27 更新于 3年前

7zip-bin-wrapper

7zip-bin 的包装脚本

解析来自 7za 的输出,创建进度事件。

此包使用的参数:(无法使用您自己)

  • -bs??
  • -y

从 7za 输出行创建的进度:

/^(\d+[%M])(?: - )?(.*)$/

Data Define:

interface IStatusReport {
    progress: number; // 0 ~ 100
    message: string;
}

interface TheHandler {
    on(event: 'progress', cb: (progress: IStatusReport) => void): this;
    on(event: 'output', cb: (data: string) => void): this;
    /** by default, 7z will run at nextTick, but you can use hold() to prevent it */
    hold(): void;
    /** terminate 7z process */
    cancel(): Promise<void>;
    /** command line to run */
    readonly commandline: ReadonlyArray<string>;
    /** 7z's cwd */
    readonly cwd: string;
    /** wait process complete */
    promise(): Promise<void>;
}

Usage:

import { sevenZip, sevenZipCli, extract, compress } from '7zip-bin-wrapper';

let handler: TheHandler;

// run raw command
handler = sevenZip('x', 'xxx.7z');
// run raw command, with spawn Option
handler = sevenZip({ cwd: '/tmp' }, 'x', 'xxx.7z');

// prevent add -y to 7za, and inherit stdin
handler = sevenZipCli('x', 'xxx.7z');

handler = extract('xxx.7z', 'some/where/else');
handler = compress('xxx.7z', 'to/include/', 'another/include/');

7zip-bin-wrapper

Wrapper script for 7zip-bin

Parsing output from 7za, create progress event.

Params used by this package: (not able to use your self)

  • -bs??
  • -y

Progress created from 7za output line:

/^(\d+[%M])(?: - )?(.*)$/

Data Define:

interface IStatusReport {
    progress: number; // 0 ~ 100
    message: string;
}

interface TheHandler {
    on(event: 'progress', cb: (progress: IStatusReport) => void): this;
    on(event: 'output', cb: (data: string) => void): this;
    /** by default, 7z will run at nextTick, but you can use hold() to prevent it */
    hold(): void;
    /** terminate 7z process */
    cancel(): Promise<void>;
    /** command line to run */
    readonly commandline: ReadonlyArray<string>;
    /** 7z's cwd */
    readonly cwd: string;
    /** wait process complete */
    promise(): Promise<void>;
}

Usage:

import { sevenZip, sevenZipCli, extract, compress } from '7zip-bin-wrapper';

let handler: TheHandler;

// run raw command
handler = sevenZip('x', 'xxx.7z');
// run raw command, with spawn Option
handler = sevenZip({ cwd: '/tmp' }, 'x', 'xxx.7z');

// prevent add -y to 7za, and inherit stdin
handler = sevenZipCli('x', 'xxx.7z');

handler = extract('xxx.7z', 'some/where/else');
handler = compress('xxx.7z', 'to/include/', 'another/include/');
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文