util: Add function to check for Android sparse image magic
This commit is contained in:
parent
941d892c6e
commit
c6eea8085b
1 changed files with 15 additions and 0 deletions
15
src/util/sparse.ts
Normal file
15
src/util/sparse.ts
Normal 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()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue