當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。