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


TypeScript fs.open函数代码示例

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