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


TypeScript fs-extra.createWriteStream函数代码示例

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


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

示例1:

        .then(res => {
            let resStream = res.body;
            let writeStream = FS.createWriteStream(tmpPackagePath);

            resStream.pipe(writeStream);

            return Promise.for(writeStream, 'close', [resStream]);
        })
开发者ID:vilic,项目名称:rvm,代码行数:8,代码来源:index.ts

示例2: Promise

  new Promise(async (resolve, reject) => {
    const content = /jsx?$/.test(path.extname(file)) ? await format(raw) : raw
    const stream = fs.createWriteStream(file)

    stream.write(content, 'utf-8')
    stream.on('finish', () => resolve())
    stream.on('error', err => reject(err))
    stream.end()
  })
开发者ID:leslieSie,项目名称:docz,代码行数:9,代码来源:fs.ts

示例3: createArchive

async function createArchive(ref: string): Promise<any> {
  const tar = spawn('git', ['archive', '--format', 'tar.gz', ref])
  const file = tmp.fileSync({postfix: '.tar.gz'})
  const write = tar.stdout.pipe(fs.createWriteStream(file.name))

  return new Promise((resolve, reject) => {
    write.on('close', () => resolve(file.name))
    write.on('error', reject)
  })
}
开发者ID:jimmyurl,项目名称:cli,代码行数:10,代码来源:git.ts

示例4: Promise

    .then(() => new Promise((resolve, reject) => {
      const rd = fs.createReadStream(from);
      rd.on('error', (err: Error) => reject(err));

      const wr = fs.createWriteStream(to);
      wr.on('error', (err: Error) => reject(err));
      wr.on('close', () => resolve());

      rd.pipe(wr);
    }));
开发者ID:3L4CKD4RK,项目名称:angular-cli,代码行数:10,代码来源:fs.ts

示例5:

  return new Promise<void>((resolve, reject) => {
    const rs = fs.createReadStream(from);
    const ws = fs.createWriteStream(to);

    rs.on('error', reject);
    ws.on('error', reject);
    ws.on('close', resolve);

    rs.pipe(ws);
  });
开发者ID:headinclouds,项目名称:angular-cli,代码行数:10,代码来源:build.ts

示例6: dataExport

async function dataExport() {
    await db.connect()

    const slugs = (await fs.readFile("/Users/mispy/tmp/urls.txt", "utf8")).split("\n").filter(s => s.trim())
    const slugToId = await Chart.mapSlugsToIds()
    const idsToGet = slugs.map(slug => slugToId[slug])

    const variables = await db.query("SELECT v.name, v.id FROM variables v JOIN chart_dimensions cd ON cd.variableId=v.id WHERE cd.chartId IN (?)", [idsToGet])
    const variableIds = variables.map((v: any) => v.id)
    const stream = fs.createWriteStream("/Users/mispy/tmp/sdgs.csv")

    // From dataset CSV export
    const csvHeader = ["Entity", "Year"]
    for (const variable of variables) {
        csvHeader.push(variable.name)
    }

    const columnIndexByVariableId: {[key: number]: number} = {}
    for (const variable of variables) {
        columnIndexByVariableId[variable.id] = csvHeader.indexOf(variable.name)
    }

    stream.write(csvRow(csvHeader))

    const data = await db.query(`
        SELECT e.name AS entity, dv.year, dv.value, dv.variableId FROM data_values dv
        JOIN variables v ON v.id=dv.variableId
        JOIN entities e ON dv.entityId=e.id
        WHERE v.id IN (?)
        ORDER BY e.name ASC, dv.year ASC, dv.variableId ASC`, [variableIds])

    let row: string[] = []
    for (const datum of data) {
        if (datum.entity !== row[0] || datum.year !== row[1]) {
            // New row
            if (row.length) {
                stream.write(csvRow(row))
            }
            row = [datum.entity, datum.year]
            for (const variable of variables) {
                row.push("")
            }
        }

        row[columnIndexByVariableId[datum.variableId]] = datum.value
    }

    // Final row
    stream.write(csvRow(row))

    stream.end()

    await db.end()
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:54,代码来源:exportSDGTrackerData.ts

示例7: download

  async download(url: string, targetFilePath: string) {
    await fs.mkdirp(path.dirname(targetFilePath));
    const writeStream = fs.createWriteStream(targetFilePath);
    await new Promise((resolve, reject) => {
      const downloadStream = got.stream(url);
      downloadStream.pipe(writeStream);

      downloadStream.on('error', error => reject(error));
      writeStream.on('error', error => reject(error));
      writeStream.on('close', () => resolve());
    });
  }
开发者ID:electron-userland,项目名称:electron-download,代码行数:12,代码来源:GotDownloader.ts

示例8: makeArchive

function makeArchive(app: string, includeDotfiles: boolean) {
  // create a file to stream archive data to.
  const { name: tarPath } = tmp.fileSync({
    discardDescriptor: true,
    prefix: `${app}-deploy-`,
    postfix: '.tar.gz'
  });
  const output = fs.createWriteStream(tarPath);
  const archive = archiver('tar', {
    gzip: true
  });

  // listen for all archive data to be written
  output.on('close', () => {
    // print something?
  });

  // good practice to catch warnings (ie stat failures and other non-blocking errors)
  archive.on('warning', (err) => {
    if (err.code === 'ENOENT') {
      // log warning
    } else {
      // throw error
      throw err;
    }
  });

  // good practice to catch this error explicitly
  archive.on('error', (err) => {
    throw err;
  });

  // pipe archive data to the file
  archive.pipe(output);

  return globby('**', {
    dot: includeDotfiles,
    gitignore: true,
    gitignoreName: '.skyignore'
  })
    .then((paths: [string]) => {
      paths.forEach((path) => {
        archive.file(path, {
          name: path
        });
      });
      // finalize the archive (ie we are done appending files but streams have to finish yet)
      return archive.finalize();
    })
    .then(() => {
      return tarPath;
    });
}
开发者ID:SkygearIO,项目名称:skycli,代码行数:53,代码来源:deploy.ts

示例9: logError

function logError(err: Error) {
  let p = path.join(cacheDir, 'weather.log')
  let log = fs.createWriteStream(p)
  log.write(new Date() + '\n')
  log.write(err.stack + '\n')
  console.log(`#[fg=red]${p.replace(os.homedir(), '~')}`)
  try {
    fs.removeSync(path.join(cacheDir, 'weather.json'))
  } catch (err) {
    console.error(err)
    notify(err.stack)
  }
}
开发者ID:dickeyxxx,项目名称:tmux-weather,代码行数:13,代码来源:tmux-weather.ts

示例10: Promise

  return new Promise((resolve, reject) => {
    const writeStream = createWriteStream(destPath);

    writeStream.on('error', (err: Error) => {
      reject(err);
    });

    writeStream.on('close', () => {
      resolve();
    });

    createReadStream(srcPath).pipe(writeStream);
  });
开发者ID:Kode-Kitchen,项目名称:ionic-app-scripts,代码行数:13,代码来源:helpers.ts


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