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

TypeScript fs.open函数代码示例

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

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



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

示例1: readFile

    readFile: function readFile(file: any, options: any, callback: any) {
      setupManifest()
      const entry = manifest[file]
      if (!entry || !isString(file)) {
        return originalReadFile.apply(fs, arguments)
      }
      const [offset, length] = entry
      const resourceOffset = resourceStart + offset
      const encoding = isString(options) ? options : null
      callback = typeof options === 'function' ? options : callback

      fs.open(process.execPath, 'r', function(err: Error, fd: number) {
        if (err) return callback(err, null)
        fs.read(fd, Buffer.alloc(length), 0, length, resourceOffset, function(
          error: Error,
          bytesRead: number,
          result: Buffer
        ) {
          if (error) {
            return fs.close(fd, function() {
              callback(error, null)
            })
          }
          fs.close(fd, function(err: Error) {
            if (err) {
              return callback(err, result)
            }
            callback(err, encoding ? result.toString(encoding) : result)
          })
        })
      })
    },
开发者ID:zavarat,项目名称:nexe,代码行数:32,代码来源:shim-fs.ts


示例2: opened

	args.map(function(path, i): void {
		// '-' represents stdin, which is already open.
		// Special-case it.
		if (path === '-') {
			files[i] = process.stdin;
			// if we've opened all of the files, pipe them
			// to stdout.
			opened();
			return;
		}
		fs.open(path, 'r', function(err: any, fd: any): void {
			if (err) {
				// if we couldn't open the specified
				// file we should print a message but
				// not exit early - we need to process
				// as many inputs as we can.
				files[i] = null;
				code = 1;
				let msg = pathToScript + ': ' + err.message + '\n';
				process.stderr.write(msg, opened);
				return;
			}
			files[i] = fs.createReadStream(path, {fd: fd});
			opened();
		});
	});
开发者ID:anuragagarwal561994,项目名称:browsix,代码行数:26,代码来源:head.ts


示例3: async

		return new Promise<string>((resolve, reject) => {
			const dir = path.join('..', 'Projects', 'Repository');
			const parenthash = id;

			if (Project.checkFilename(filename)) {
				Project.error(socket, 'Bad filename.');
				return parenthash;
			}

			git.readTreeEmpty(dir);
			git.readTree(dir, parenthash);

			fs.open(path.join('..', 'Projects', 'Temp', 'whatever'), 'w', (err, fd) => {
				if (err) {
					throw 'Error opening file: ' + err;
				}
			
				fs.write(fd, buffer, 0, buffer.length, null, (err) => {
					if (err) throw 'Error writing file: ' + err;
					fs.close(fd, async () => {
						const objecthash = git.hashObject(dir, path.join('..', 'Temp', 'whatever'));
						git.addToIndex(dir, objecthash, 'Assets/' + filename);
						const treehash = git.writeTree(dir);
						const sha = git.commitTree(dir, treehash, parenthash);
						resolve(sha);
					});
				});
			});
		});
开发者ID:KTXSoftware,项目名称:KodeGarden,代码行数:29,代码来源:Project.ts


示例4: it

    it('should read', async function (done) {
        this.timeout(1000000);

        try {
            let filePath = "/Users/epi/Projects/santelab/santelab_dane_2016_05_03/WYNIKI.dbt";
            fs.open(filePath, 'r', async function (rs) {
                console.log('opnd')
                let reader = new DbtReader(rs, '852');
                console.log('opnd2')
                // let parser = new Parser(rs, '852');

                let h = await reader.parseHeader();
                console.log('HHHH')
                console.log(h);
                for (let i = 0; i < 10; i++) {
                    let b = await reader.readBlock(i, h);
                    console.log(b);
                }
            });


        } catch (error) {
            done(error);
        }
    });
开发者ID:episage,项目名称:typescript-dbf-parser,代码行数:25,代码来源:dbt.spec.ts


示例5: function

			fs.stat(path, function(err: any, stats: fs.Stats): void {
				if (err) {
					// if we couldn't stat the
					// specified file we should
					// create it.  Pass 'x' for
					// the CREAT flag.
					fs.open(path, 'wx', function(oerr:  any, fd: number): void {
						if (oerr) {
							// now we're in trouble and
							// we should try other files instead.
							code = 1;
							let msg = pathToScript + ': ' + oerr + '\n';
							process.stderr.write(msg, finished);
						}
						// thats it - close the sucker.
						fs.close(fd, finished);
					});
				} else {
					// file exists - just use utimes,
					// no need to open it.
					fs.utimes(path, now, now, (uerr: any) => {
						if (uerr) {
							code = 1;
							process.stderr.write('utimes: ' + uerr.message + '\n', finished);
							return;
						}
						finished();
					});
				}
			});
开发者ID:anuragagarwal561994,项目名称:browsix,代码行数:30,代码来源:touch.ts


示例6: readQueryFile

	protected readQueryFile(queryFile: string): Q.Promise<any> {
		let deferred = Q.defer<any>();

		// check if the query file exists
		fs.open(queryFile, "r", function(err, fd) {
			if(err) {
				deferred.reject(err);
			} else {
				fs.readFile(queryFile, {encoding: 'utf-8'}, function(err, query) {
					if(err) {
						deferred.reject(err);
					} else {
						// check if we got a valid query json file
						try {
							let queryJSON: JSONQuery = JSON.parse(query);

							deferred.resolve(queryJSON);
						} catch(err) {
							deferred.reject('ERROR: Could not parse query JSON file. Error = '+err);
						};

					}
				});
			}
		});

		return deferred.promise;
	}
开发者ID:fabianTMC,项目名称:smart-query-cache,代码行数:28,代码来源:genericEngine.ts


示例7: Promise

		new Promise((resolve, reject) => {

			// Create a file with a name of the form 'file._id.<ext>', where <ext> is the extension of the original file
			var filepath = __dirname + '/../' + file._id + '.' + file.filename.substr(file.filename.lastIndexOf('.') + 1);

			// Check whether the file already exists
			fs.open(filepath, 'r', (err: Error, fd: any) => {
				if (!err) {
					// File already exits
					fs.closeSync(fd);
					resolve(null);
				}
				else {
					// File does not exist...create it
					var fs_write_stream = fs.createWriteStream(filepath);

					var gfs = Grid(conn.db);

					// Read from mongodb
					var readstream = gfs.createReadStream({ _id: file._id });
					readstream.pipe(fs_write_stream);
					fs_write_stream.on('close', () => {
						resolve(null);
					});
					fs_write_stream.on('error', () => {
						err = Error('file creation error: ' + filepath);
						reject(err);
					});
				}
			});
		});
开发者ID:roderickmonk,项目名称:rod-monk-sample-repo-ng2,代码行数:31,代码来源:GridFS.ts


示例8: setTimeout

		args.map(function(path: string, i: number): void {
			if (path === '-') {
				files[i] = process.stdin;
				// if we've opened all of the files, pipe them to
				// stdout.
				if (++opened === args.length)
					setTimeout(concat, 0, files, process.stdout, code);
				return;
			}
			fs.open(path, 'r', function(err: any, fd: any): void {
				if (err) {
					// if we couldn't open the
					// specified file we should
					// print a message but not
					// exit early - we need to
					// process as many inputs as
					// we can.
					files[i] = null;
					code = 1;
					log(err.message);
				} else {
					files[i] = fs.createReadStream(path, {fd: fd});
				}
				// if we've opened all of the files,
				// pipe them to stdout.
				if (++opened === args.length)
					setTimeout(concat, 0, files, process.stdout, code);
			});
		});
开发者ID:anuragagarwal561994,项目名称:browsix,代码行数:29,代码来源:cat.ts


示例9: reject

 return new Promise<any>((resolve, reject) => {
     fs.open(filePath, "r", (err: any, fd: any) => {
         if (err) {
             reject(err);
         } else {
             resolve(fd);
         }
     });
 });
开发者ID:eez-open,项目名称:studio,代码行数:9,代码来源:util-electron.ts


示例10: useFile

 private useFile(file: string) {
     this.queue = [];
     this.queueFlushable = false;
     fs.open(file, "a+", 0o666, (err, fd: number) => {
         this.fd = fd;
         this.queueFlushable = true;
         this.writeQueue();
     });
 }
开发者ID:hospitalityPulse,项目名称:hospitalityPulseOpen,代码行数:9,代码来源:Logger.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript fs.openSync函数代码示例发布时间:2022-05-25
下一篇:
TypeScript fs.mkdtempSync函数代码示例发布时间: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