• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript fs-extra.emptyDir函数代码示例发布时间:2022-05-25
下一篇:
TypeScript fs-extra.createReadStream函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap