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

TypeScript fs.read函数代码示例

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

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



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

示例1: Promise

 return new Promise((fulfill, reject) => {
   fs.read(fileDescriptor, allocBuffer, 0, MAX_BYTES, 0, (err, bytesRead, _) => {
     closeAsync(fileDescriptor);
     if (err) { reject(err) }
     else { fulfill(isBinaryCheck(allocBuffer, bytesRead)); }
   });
 });
开发者ID:gjtorikian,项目名称:isBinaryFile,代码行数:7,代码来源:index.ts


示例2: Buffer

  tesData.visit(fd, (offset, size, type, parent) => {
    remaining++;
    var buffer = new Buffer(size);
    fs.read(fd, buffer, 0, size, offset, (err, bytesRead, buffer) => {
      tesData.readRecord(buffer, context).then(record => {
        tesData.writeRecord(record, context).then(outBuffer => {
          fs.write(outFd, outBuffer, 0, outBuffer.length, offset, (err, written, str) => {
            remaining--;
            finished++;

            if (finished % 10000 === 0) {
              console.log(`finished writing ${finished} records...`);
            }

            if (remaining === 0) {
              fs.closeSync(fd);
              fs.closeSync(outFd);
              getFileHash(path, hash => {
                getFileHash(outPath, otherHash => {
                  if (hash === otherHash) {
                    console.log(`Output file ${outPath} matches exactly!`);
                  }
                  else {
                    console.log(`Output file ${outPath} is not exactly the same - NOPOOOOOO!`);
                  }
                })
              })
            }
          });
        });
      });
    })
  }, err => {
开发者ID:fcrick,项目名称:tes-data,代码行数:33,代码来源:rebuildFile.ts


示例3: Promise

 return await new Promise((resolve) => {
   fs.read(fd, Buffer.alloc(24), 0, 24, 0,
    (err, bytesRead, buffer) => resolve({
      width: buffer.readUInt32BE(16),
      height: buffer.readUInt32BE(20)
    }))
 })
开发者ID:nylen,项目名称:chromeless,代码行数:7,代码来源:util.test.ts


示例4: Buffer

 tesData.visit(fd, (offset, size, type) => {
   remaining++;
   if (!outFds[type]) {
     var outFile = `${outDir}/${type}.json`;
     outFds[type] = fs.openSync(outFile, 'w');
   }
   var buffer = new Buffer(size);
   fs.read(fd, buffer, 0, size, offset, (err, bytesRead, buffer) => {
     tesData.readRecord(buffer, context)
       .then(record => {
         fs.write(outFds[type], JSON.stringify(record, null, 2) + ',\n', err => onDone(err));
       });
   });
 }, err => onDone(err));
开发者ID:fcrick,项目名称:tes-data,代码行数:14,代码来源:getAllByType.ts


示例5: resolve

			return this.fd.then(fd => {
				fs.read(fd, this.buf, this.bufEnd, size, null, (err, bytesRead, buf) => {
					if (err) return reject(err);
					if (!bytesRead) {
						this.atEOF = true;
						this.resolvePush();
						return resolve(false);
					}
					this.bufEnd += bytesRead;
					// throw new Error([...this.buf].map(x => x.toString(16)).join(' '));
					this.resolvePush();
					resolve(true);
				});
			});
开发者ID:AdmiralZachbar,项目名称:Pokemon-Showdown,代码行数:14,代码来源:fs.ts


示例6: readBlock

    public async readBlock(blockNumber: number, memoHeader: Models.MemoFileHeader) {
        let offset = blockNumber * memoHeader.blockLength;

        let infoBuffer = Buffer.alloc(8, 0, 'binary');

        await fs.read(this.memoFileDescriptior, infoBuffer, offset, 8, 0);

        var infoReader = new BufferReader(infoBuffer);

        let reserved00h = infoReader.readBytes(4);
        const shouldBe = Buffer.from([0xFF, 0xFF, 0x08, 0x00]);
        if (!reserved00h.equals(shouldBe)) {
            throw "Read buffer ${reserved00h} is not equal to ${shouldBe}.";
        }

        let length = infoReader.read32bitUInt();

        let dataBuffer = Buffer.alloc(length, 0, 'binary');
        await fs.read(this.memoFileDescriptior, dataBuffer, offset + 8, length, 0);
        let dataReader = new BufferReader(dataBuffer);

        let text = dataReader.readString(length, this.encoding);
    }
开发者ID:episage,项目名称:typescript-dbf-parser,代码行数:23,代码来源:DbtReader.ts


示例7: reject

    return new Promise<Buffer>((resolve:PromiseResolve<Buffer>, reject:PromiseReject) => {
      let out_buf = Buffer.allocUnsafe(read_size);

      fs.read(this._fd, out_buf, 0, read_size, cur_offset, (err:Error, bytes_read:number, buf:Buffer) => {
        if (!isNullOrUndefined(err)) {
          reject(err);
        } else {
          if (bytes_read < out_buf.length) {
            resolve(out_buf.slice(0, bytes_read)); // prevent placing unsafe data into output buffer
          } else {
            resolve(out_buf);
          }
        }
      });
    });
开发者ID:zenwarr,项目名称:microhex-js,代码行数:15,代码来源:source.ts


示例8: Buffer

    return new Promise<Buffer>((resolve, reject) => {
        try {
            let buffer = new Buffer(length);

            fs.read(fd, buffer, 0, length, position, (err, bytesRead, buffer) => {
                if (err) {
                    return reject(err);
                }

                return resolve(buffer);
            });
        } catch (exception) {
            return reject(exception);
        }
    });
开发者ID:haapanen,项目名称:cross-server-chat,代码行数:15,代码来源:Application.ts


示例9: reject

 return new Promise<{ bytesRead: number; buffer: Buffer }>((resolve, reject) => {
     fs.read(
         fd,
         buffer,
         offset,
         length,
         position,
         (err: any, bytesRead: number, buffer: Buffer) => {
             if (err) {
                 reject(err);
             } else {
                 resolve({ bytesRead, buffer });
             }
         }
     );
 });
开发者ID:eez-open,项目名称:studio,代码行数:16,代码来源:util-electron.ts


示例10: function

 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,代码行数:20,代码来源:shim-fs.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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