fs-extra#read TypeScript Examples
The following examples show how to use
fs-extra#read.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileWithEmbeddedBlockMapDifferentialDownloader.ts From electron-differential-updater with MIT License | 6 votes |
async function readEmbeddedBlockMapData(file: string): Promise<BlockMap> {
const fd = await open(file, "r");
try {
const fileSize = (await fstat(fd)).size;
const sizeBuffer = Buffer.allocUnsafe(4);
await read(
fd,
sizeBuffer,
0,
sizeBuffer.length,
fileSize - sizeBuffer.length
);
const dataBuffer = Buffer.allocUnsafe(sizeBuffer.readUInt32BE(0));
await read(
fd,
dataBuffer,
0,
dataBuffer.length,
fileSize - sizeBuffer.length - dataBuffer.length
);
await close(fd);
return readBlockMap(dataBuffer);
} catch (e) {
await close(fd);
throw e;
}
}