...

Package binpatch

import "github.com/sassoftware/relic/lib/binpatch"
Overview
Index

Overview ▾

A means of conveying a series of edits to binary files. Each item in a patchset consists of an offset into the old file, the number of bytes to remove, and the octet string to replace it with.

Constants

const (
    MimeType = "application/x-binary-patch"
)

type PatchHeader

type PatchHeader struct {
    Offset           int64
    OldSize, NewSize uint32
}

type PatchSet

type PatchSet struct {
    Patches []PatchHeader
    Blobs   [][]byte
}

func Load

func Load(blob []byte) (*PatchSet, error)

Unmarshal a PatchSet from bytes

func New

func New() *PatchSet

Create a new, empty PatchSet

func (*PatchSet) Add

func (p *PatchSet) Add(offset, oldSize int64, blob []byte)

Add a new patch region to a PatchSet. The bytes beginning at "offset" and running for "oldSize" are removed and replaced with "blob". oldSize may be 0.

func (*PatchSet) Apply

func (p *PatchSet) Apply(infile *os.File, outpath string) error

Apply a PatchSet by taking the input file, transforming it, and writing the result to outpath. If outpath is the same name as infile then the file will be updated in-place if a direct overwrite is possible. If they are not the same file, or the patch requires moving parts of the old file, then the output will be written to a temporary file then renamed over the destination path.

func (*PatchSet) Dump

func (p *PatchSet) Dump() []byte

Marshal a PatchSet to bytes

type PatchSetHeader

type PatchSetHeader struct {
    Version, NumPatches uint32
}