A go (golang) library for decoding android sparse image formatted files into raw images.
For a full example see example utility in ./cmd/
Using the writer. The performance of the writer is much better than the performance of the reader, as we can seek-past any "don't care" chunks in the sparse format, instead of writing random data.
func simg2img(in_filename, out_filename string) error {
in, err := os.Open(in_filename)
if err != nil {
return err
}
defer in.Close()
out, err := os.OpenFile(out_filename, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer out.Close()
writer := sparse.Simg2imgWriter(out)
_, err = io.Copy(writer, in)
return err
}
Using the reader (slower!! Read Above!)
func simg2img_alt(in_filename, out_filename string) error {
in, err := os.Open(in_filename)
if err != nil {
return err
}
defer in.Close()
out, err := os.OpenFile(out_filename, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer out.Close()
reader, err := sparse.Simg2imgReader(in)
if err != nil {
return err
}
_, err = io.Copy(out, reader)
return err
}
See LICENSE file.