UNPKG

ethstorage-sdk-ts

Version:

eip-4844 blobs upload sdk from ethstorage-sdk

39 lines (36 loc) 947 B
import fs from "fs"; import { BaseEthStorage } from "./ethstorage"; export class EthStorage extends BaseEthStorage { getFileInfo(filePath: string) { console.log("getFileInfo", filePath); const fileStat = fs.statSync(filePath); if (fileStat.isFile()) { const name = filePath.substring(filePath.lastIndexOf("/") + 1); return { isFile: true, isDirectory: false, name: name, size: fileStat.size, path: filePath, }; } return { isFile: false, isDirectory: fileStat.isDirectory(), }; } async getFileChunk( filePath: string, fileSize: number, start: number, end: number ): Promise<Buffer> { end = end > fileSize ? fileSize : end; const length = end - start; const buf = Buffer.alloc(length); const fd = fs.openSync(filePath, "r"); fs.readSync(fd, buf, 0, length, start); fs.closeSync(fd); return buf; } }