当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript archiver.create函数代码示例

本文整理汇总了TypeScript中archiver.create函数的典型用法代码示例。如果您正苦于以下问题:TypeScript create函数的具体用法?TypeScript create怎么用?TypeScript create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了create函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

    return new Promise<string>((resolve, reject) => {
        
        let zipFileName = "geoserver_" + requestTimestamp.toString() + ".zip";
        let zipFilePath = config.get("save_path") + zipFileName;
        let zipStream = fs.createWriteStream(zipFilePath);
        let archive = archiver.create("zip", {});

        zipStream.on("close", function() {
            resolve(zipFileName);
        });
        
        archive.on("error", (err: any) => {
            reject(err);
        });
        
        archive.pipe(zipStream);

        for (let fileName of filesToZip) {
            let fileNameWithoutTimestamp = fileName.replace(/[0-9]/g, "");
            let fn = config.get("save_path") + fileName;
            archive.append(fs.createReadStream(fn), { name: fileNameWithoutTimestamp });
            fs.unlink(fn, (err: any) => {
                if (err) throw err;
            });
            
        }
        
        archive.finalize();        
                
                
    });
开发者ID:usa-npn,项目名称:pop-service,代码行数:31,代码来源:zipBuilder.ts

示例2: function

  create: function(filePath: string): {commitAsync: () => Promise<void>, writeAsync: (fileName: string, data: any) => Promise<void>} {
    // Initialize the variables.
    let archive = archiver.create('zip', {store: true});
    let isWriting = false;
    let tempFilePath = `${filePath}.mrtmp`;

    // Returns the zip archive.
    return {
      /**
       * Promises to commit the archive.
       * @return The promise to commit the archive.
       */
      commitAsync: async function(): Promise<void> {
        if (isWriting) {
          archive.finalize();
          await mio.promise<void>(callback => fs.rename(tempFilePath, filePath, callback));
        }
      },

      /**
       * Promises to write the file.
       * @param fileName The file name.
       * @param data The data.
       * @return The promise to write the file.
       */
      writeAsync: async function(fileName: string, data: any): Promise<void> {
        if (!isWriting) {
          await createDirectoriesAsync(tempFilePath);
          archive.pipe(fs.createWriteStream(tempFilePath));
          isWriting = true;
        }
        archive.append(data, {name: fileName});
      }
    };
  }
开发者ID:HigorSevilha,项目名称:mangarack,代码行数:35,代码来源:zipService.ts

示例3: downloadSeriesItemAsync

export async function downloadSeriesItemAsync(series: mio.IScraperSeries, seriesChapter: mio.IScraperSeriesChapter) {
  let chapterPath = shared.path.normal(series.providerName, series.title, seriesChapter.name + shared.extension.cbz);
  let chapterExists = await fs.pathExists(chapterPath);
  if (!chapterExists) {
    console.log(`Fetching ${seriesChapter.name}`);
    let chapter = archiver.create('zip', {store: true});
    let timer = new mio.Timer();
    await fs.ensureDir(path.dirname(chapterPath));
    chapter.pipe(fs.createWriteStream(chapterPath + shared.extension.tmp));
    await mio.usingAsync(seriesChapter.iteratorAsync(), async iterator => {
      try {
        await archiveAsync(chapter, iterator);
        chapter.finalize();
        await fs.rename(chapterPath + shared.extension.tmp, chapterPath);
        console.log(`Finished ${seriesChapter.name} (${timer})`);
      } catch (error) {
        await fs.unlink(chapterPath + shared.extension.tmp);
        throw error;
      } finally {
        chapter.abort();
      }
    });
  }
}
开发者ID:Deathspike,项目名称:mangarack,代码行数:24,代码来源:download.ts

示例4: Archiver

    decodeStrings: true,
    encoding: 'test',
    highWaterMark: 1,
    objectmode: true,
    comment: 'test',
    forceLocalTime: true,
    forceZip64: true,
    store: true,
    zlib: {},
    gzip: true,
    gzipOptions: {},
};

Archiver('zip', options);

const archiver = Archiver.create('zip');

const writeStream = fs.createWriteStream('./archiver.d.ts');
const readStream = fs.createReadStream('./archiver.d.ts');

archiver.abort();

archiver.pipe(writeStream);
archiver.append(readStream, { name: 'archiver.d.ts' });
archiver.append(readStream, { date: '05/05/1991' });
archiver.append(readStream, { date: new Date() });
archiver.append(readStream, { mode: 1 });
archiver.append(readStream, { mode: 1, stats: new fs.Stats() });

archiver.append(readStream, {name: 'archiver.d.ts'})
.append(readStream, {name: 'archiver.d.ts'});
开发者ID:DavidM77,项目名称:DefinitelyTyped,代码行数:31,代码来源:archiver-tests.ts

示例5: generate

    async generate(): Promise<void> {
        let project = this.project;

        let { name, version } = project;

        let artifacts: ArtifactMetadataItem[] = [];

        let metadata: ArtifactMetadata = {
            name,
            version,
            artifacts
        };

        let defaultIdPlugin: Plugin | undefined;

        for (let plugin of project.plugins) {
            if (plugin.processArtifactMetadata) {
                await plugin.processArtifactMetadata(metadata);
            }

            if (plugin.getDefaultArtifactId) {
                defaultIdPlugin = plugin;
            }
        }

        for (let platform of project.platforms) {
            console.log();
            console.log(
                project.platformSpecified ?
                    `Generating artifact of project ${Style.id(name)} ${Style.dim(`(${platform.name})`)}...` :
                    `Generating artifact of project ${Style.id(name)}...`
            );
            console.log();

            let idTemplate = this.config.id || (
                defaultIdPlugin ?
                    await defaultIdPlugin.getDefaultArtifactId!(project.platformSpecified ? platform : undefined) :
                    (project.platformSpecified ? '{name}-{platform}' : '{name}')
            );

            let id = project.renderTemplate(idTemplate, {
                platform: project.platformSpecified ? platform.name : undefined
            });

            let archiver = Archiver.create('zip', {});

            let mappings = this
                .mappings
                .filter(mapping => !mapping.platformSet || mapping.platformSet.has(platform.name));

            await this.walk(mappings, platform, archiver);

            archiver.finalize();

            let path = Path.join(project.distDir, `${id}.zip`);

            let writeStream = FS.createWriteStream(path);

            archiver.pipe(writeStream);

            await awaitable(writeStream, 'close', [archiver]);

            console.log();
            console.log(`Artifact generated at path ${Style.path(path)}.`);

            artifacts.push({
                id,
                platform: project.platformSpecified ? platform.name : undefined,
                path: Path.relative(project.distDir, path)
            });
        }

        let metadataFilePath = Path.join(project.distDir, `${name}.json`);
        let metadataJSON = JSON.stringify(metadata, undefined, 4);

        await acall<void>(FS.writeFile, metadataFilePath, metadataJSON);

        console.log();
        console.log(`Artifact metadata generated at path ${Style.path(metadataFilePath)}.`);
    }
开发者ID:vilic,项目名称:henge,代码行数:80,代码来源:artifact.ts


注:本文中的archiver.create函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。