本文整理汇总了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)); }
});
});
示例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 => {
示例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)
}))
})
示例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));
示例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);
});
});
示例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);
}
示例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);
}
}
});
});
示例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);
}
});
示例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 });
}
}
);
});
示例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)
})
})
})