本文整理匯總了TypeScript中fs-extra-p.read函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript read函數的具體用法?TypeScript read怎麽用?TypeScript read使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了read函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: readEmbeddedBlockMapData
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
}
}
開發者ID:electron-userland,項目名稱:electron-builder,代碼行數:18,代碼來源:FileWithEmbeddedBlockMapDifferentialDownloader.ts
示例2: readEmbeddedBlockMapData
export async function readEmbeddedBlockMapData(file: string) {
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)
const inflateRaw: any = BluebirdPromise.promisify(require("zlib").inflateRaw)
return (await inflateRaw(dataBuffer)).toString()
}
catch (e) {
await close(fd)
throw e
}
}
示例3: checkIcon
async function checkIcon(file: string): Promise<void> {
const fd = await open(file, "r")
const buffer = new Buffer(512)
try {
await read(fd, buffer, 0, buffer.length, 0)
}
finally {
await close(fd)
}
const sizes = parseIco(buffer)
for (let size of sizes) {
if (size.w >= 256 && size.h >= 256) {
return
}
}
throw new Error("Windows icon image size must be at least 256x256")
}
示例4: computeBlocks
async function computeBlocks(inputFile: string, stat: Stats): Promise<Array<string>> {
const fd = await open(inputFile, "r")
const chunkSize = 64 * 1024
const buffer = Buffer.allocUnsafe(chunkSize)
const size = stat.size
const blocks = []
for (let offset = 0; offset < size; offset += chunkSize) {
const actualChunkSize = Math.min(size - offset, chunkSize)
await read(fd, buffer, 0, actualChunkSize, offset)
const hash = createHash("sha256")
hash.update(actualChunkSize === chunkSize ? buffer : buffer.slice(0, actualChunkSize))
blocks.push(hash.digest("base64"))
}
return blocks
}
示例5: safeLoad
packed: async context => {
const outDir = context.outDir
outDirs.push(outDir)
const targetOutDir = path.join(outDir, "nsis-web")
const updateInfoFile = path.join(targetOutDir, "latest.yml")
const updateInfo: UpdateInfo = safeLoad(await readFile(updateInfoFile, "utf-8"))
const fd = await open(path.join(targetOutDir, `TestApp-${version}-x64.nsis.7z`), "r")
try {
const packageInfo = updateInfo.packages!!.x64
const buffer = Buffer.allocUnsafe(packageInfo.blockMapSize!!)
await read(fd, buffer, 0, buffer.length, packageInfo.size - buffer.length)
const inflateRaw: any = BluebirdPromise.promisify(require("zlib").inflateRaw)
const blockMapData = (await inflateRaw(buffer)).toString()
await writeFile(path.join(outDir, "win-unpacked", BLOCK_MAP_FILE_NAME), blockMapData)
}
finally {
await close(fd)
}
}
示例6: checkIcon
async function checkIcon(file: string): Promise<void> {
const fd = await open(file, "r")
const buffer = new Buffer(512)
try {
await read(fd, buffer, 0, buffer.length, 0)
}
finally {
await close(fd)
}
if (!isIco(buffer)) {
throw new Error(`Windows icon is not valid ico file, please fix "${file}"`)
}
const sizes = parseIco(buffer)
for (let size of sizes) {
if (size!.w >= 256 && size!.h >= 256) {
return
}
}
throw new Error(`Windows icon size must be at least 256x256, please fix "${file}"`)
}