util: Add function to check for Android sparse image magic

This commit is contained in:
Danny Lin 2021-12-16 17:46:21 -08:00
parent 941d892c6e
commit c6eea8085b

15
src/util/sparse.ts Normal file
View file

@ -0,0 +1,15 @@
import { promises as fs } from 'fs'
const FILE_MAGIC = 0xed26ff3a
export async function isSparseImage(path: string) {
let file = await fs.open(path, 'r')
try {
let buf = new Uint32Array(1)
await file.read(buf, 0, 4)
return buf[0] == FILE_MAGIC
} finally {
await file.close()
}
}