kristoiv / sparse

Golang library for working with the Android Sparse Image Format (simg2img)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Golang implementation of simg2img

Overview

A go (golang) library for decoding android sparse image formatted files into raw images.

Examples

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
}

License

See LICENSE file.

About

Golang library for working with the Android Sparse Image Format (simg2img)

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Go 94.3%Language:Makefile 5.7%