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


TypeScript fs.createReadStream函数代码示例

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


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

示例1: once

	const promise = new TPromise<string>((c, e) => {
		const input = fs.createReadStream(path);
		const hash = crypto.createHash('sha1');
		const hashStream = hash as any as stream.PassThrough;
		input.pipe(hashStream);

		const done = once((err?: Error, result?: string) => {
			input.removeAllListeners();
			hashStream.removeAllListeners();

			if (err) {
				e(err);
			} else {
				c(result);
			}
		});

		input.once('error', done);
		input.once('end', done);
		hashStream.once('error', done);
		hashStream.once('data', (data: NodeBuffer) => done(null, data.toString('hex')));
	});
开发者ID:AlexxNica,项目名称:sqlopsstudio,代码行数:22,代码来源:crypto.ts

示例2: getRenderedSourceCode

 server = http.createServer(async (request, response) => {
   if (request.url) {
     if (request.url === "/") {
       response.setHeader("Content-Type", "text/html");
       response.end(await getRenderedSourceCode());
     } else {
       try {
         let filePath: string = commandArgs.fsPath.replace(/\\/g, "/");
         let lastSlashPosition = filePath.lastIndexOf('/');
         let basePath = filePath.substr(0, lastSlashPosition);
         filePath = `${basePath}${request.url}`;
         let cb = fs.statSync(filePath).size;
         response.setHeader("Content-Type", `image/${request.url.substr(request.url.lastIndexOf('.'))}`);
         response.setHeader("Content-Length", cb);
         fs.createReadStream(filePath).pipe(response);
       } catch {
         //fail
         response.end();
       }
     }
   }
 });
开发者ID:natkuhn,项目名称:vsc-print,代码行数:22,代码来源:extension.ts

示例3: if

		node.redirs.forEach(function (redir) {
			const direction = redir.direction.type.toString();
			const target = redir.target;
			var fd = redir.direction.number;

			if (direction === 'LT') {
				if (!utils.isNumber(fd)) {
					fd = 0;
				}
				cmdStreams[fd] = fs.createReadStream(target.text);
			} else if (direction === 'GT') {
				if (!utils.isNumber(fd)) {
					fd = 1;
				}
				cmdStreams[fd] = fs.createWriteStream(target.text); // truncates
			} else if (direction === 'GTGT') {
				if (!utils.isNumber(fd)) {
					fd = 1;
				}
				cmdStreams[fd] = fs.createWriteStream(target.text, {flags: 'a'});
			} else if (direction === 'LTGT') {
				if (!utils.isNumber(fd)) {
					fd = 0;
				}
				cmdStreams[fd] = fs.createWriteStream(target.text, {flags: 'a'});
			} else if (direction === 'GTAMP') {
				// TODO THIS DOESN'T REALLY WORK RIGHT NOW, FD VALUE IS PASSED DIRECTLY TO SPAWN SO IT REFERS TO PARENT'S FD. SAME GOES FOR LTAMP
				if (!utils.isNumber(fd)) {
					fd = 1;
				}
				cmdStreams[fd] = cmdStreams[Number(target.text)];
			} else if (direction === 'LTAMP') {
				if (!utils.isNumber(fd)) {
					fd = 0;
				}
				cmdStreams[fd] = cmdStreams[Number(target.text)];
			}
			// TODO MUST DETECT DUPLICATE FDs AND OPEN DUPLEX STREAM FOR THEM (e.g., "somecommand 7>thefile 7<thefile")
		});
开发者ID:bteixeira,项目名称:nodeshell,代码行数:39,代码来源:executerVisitor.ts

示例4: decodeURI

      (request, callback) => {
        const urlPath = url.parse(request.url).pathname;
        const decodedPath = decodeURI(urlPath);
        const rootlessPath = decodedPath.replace(/^\//, "");
        const filePath = join(fileRoot, rootlessPath);

        try {
          var stats = statSync(filePath);
          var stream = createReadStream(filePath);
          callback({
            headers: {
              server: "itch",
              "content-type": mime.lookup(filePath),
              "content-length": stats.size,
              "access-control-allow-origin": "*",
            },
            statusCode: 200,
            data: stream as any, // *sigh*
          });
        } catch (e) {
          logger.warn(`while serving ${request.url}, got ${e.stack}`);
          let statusCode = 400;
          switch (e.code) {
            case "ENOENT":
              statusCode = 404;
              break;
            case "EPERM":
              statusCode = 401;
              break;
          }

          callback({
            headers: {},
            statusCode,
            data: null,
          });
          return;
        }
      },
开发者ID:itchio,项目名称:itch,代码行数:39,代码来源:itch-cave-protocol.ts

示例5: readExistingTweets

function readExistingTweets(outputFilepath: string,
                            callback: (error: Error, fetchedStatuses?: {[index: string]: number}) => void) {
  let fetchedStatuses: {[index: string]: number} = {};

  // quick exit if output is undefined
  if (outputFilepath === undefined) return callback(null, fetchedStatuses);

  logger.info(`Reading existing tweets from "${outputFilepath}"`);

  let inputStream = createReadStream(outputFilepath, {flags: 'r', encoding: 'utf8'});
  inputStream.pipe(new JSONParser())
  .on('data', (status: Status) => {
    fetchedStatuses[status.id_str] = 1;
  })
  .on('error', (error: Error) => {
    callback(error);
  })
  .on('end', () => {
    logger.info(`Found ${Object.keys(fetchedStatuses).length} tweets in "${outputFilepath}"`);
    callback(null, fetchedStatuses);
  });
}
开发者ID:chbrown,项目名称:twilight,代码行数:22,代码来源:index.ts

示例6: copyFile

export function copyFile(source, target, cb) {
    var cbCalled = false;

    var rd = fs.createReadStream(source);
    rd.on('error', function(err) {
        done(err);
    });
    var wr = fs.createWriteStream(target);
    wr.on('error', function(err) {
        done(err);
    });
    wr.on('close', function(ex) {
        done();
    });
    rd.pipe(wr);

    function done(err?) {
        if (!cbCalled) {
            cb(err);
            cbCalled = true;
        }
    }
}
开发者ID:kisstkondoros,项目名称:gutter-preview,代码行数:23,代码来源:fileutil.ts

示例7: streamFile

export function streamFile(filename: string, res: ServerResponse) {
  if (!path.isAbsolute(filename)) {
    throw new Error(`stream file expects an absolute path found ${filename}`);
  }
  let mimeType = mime.lookup(filename);
  // res.writeHead(200, { "Content-Type": mimeType});
  let readstream = fs.createReadStream(filename);
  readstream.on("error", err => {
    if ((err.code = "ENOENT")) {
      // file not found
      res.statusCode = 404;
      res.end("Not Found");
    } else {
      console.error(err);
      res.statusCode = 500;
      res.end("Unknown Server Error");
    }
  });

  res.statusCode = 200;
  res.setHeader("Content-Type", mimeType);
  readstream.pipe(res);
}
开发者ID:mofax,项目名称:leafless,代码行数:23,代码来源:util.ts

示例8: Promise

	return new Promise(resolve => {
		const icons: Icon[] = [];
		const codepointsPath = require.resolve(
			'material-design-icons/iconfont/codepoints'
		);
		const rl = createInterface({
			input: createReadStream(codepointsPath, 'utf8')
		});

		rl.on('line', (line: string) => {
			const [id, unicode] = line.split(' ');

			icons.push({
				id,
				unicode
			});
		});
		rl.on('close', () => {
			resolve({
				icons
			});
		});
	});
开发者ID:gluons,项目名称:material-design-icon-chars,代码行数:23,代码来源:utils.ts

示例9: copyFile

function copyFile(source: string | Buffer, target: string | Buffer, cb: (err?: string) => void) {
    let cbCalled = false;

    let rd = fs.createReadStream(source);
    rd.on("error", function (err) {
        done(err);
    });
    let wr = fs.createWriteStream(target);
    wr.on("error", function (err) {
        done(err);
    });
    wr.on("close", function (ex) {
        done();
    });
    rd.pipe(wr);

    function done(err?) {
        if (!cbCalled) {
            cb(err);
            cbCalled = true;
        }
    }
}
开发者ID:danelkhen,项目名称:desktopbrowser,代码行数:23,代码来源:utils.ts

示例10: it

 it("should include column", function (done) {
   var rs = fs.createReadStream(__dirname + "/data/dataWithQoutes");
   csv({
     includeColumns: /TIMESTAMP/
   })
     .fromStream(rs)
     .on("header", function (header) {
       assert.equal(header.indexOf("TIMESTAMP"), 0);
       assert.equal(header.indexOf("UPDATE"), -1);
       assert.equal(header.length, 1);
     })
     .subscribe(function (j, idx) {
       assert(idx >= 0);
       if (idx === 1) {
         assert.equal(j.TIMESTAMP, "abc, def, ccc");
       }
       assert(!j.UID)
       assert(!j['BYTES SENT'])
     })
     .on("done", function () {
       done();
     });
 });
开发者ID:Keyang,项目名称:node-csvtojson,代码行数:23,代码来源:testCSVConverter2.ts


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