// copied from github.com/akavel/rsrc // LICENSE: MIT // Copyright 2013-2014 The rsrc Authors. (https://github.com/akavel/rsrc/blob/master/AUTHORS) func writeCoff(coff *coff.Coff, fnameout string) error { out, err := os.Create(fnameout) if err != nil { return err } defer out.Close() w := binutil.Writer{W: out} // write the resulting file to disk binutil.Walk(coff, func(v reflect.Value, path string) error { if binutil.Plain(v.Kind()) { w.WriteLE(v.Interface()) return nil } vv, ok := v.Interface().(binutil.SizedReader) if ok { w.WriteFromSized(vv) return binutil.WALK_SKIP } return nil }) if w.Err != nil { return fmt.Errorf("Error writing output file: %s", w.Err) } return nil }
func freezeCommon2(v reflect.Value, offset *uint32) error { if binutil.Plain(v.Kind()) { *offset += uint32(binary.Size(v.Interface())) // TODO: change to v.Type().Size() ? return nil } vv, ok := v.Interface().(Sizer) if ok { *offset += uint32(vv.Size()) return binutil.WALK_SKIP } return nil }
// Walk writes the data buffer with hexidecimal data from the structs func (vi *VersionInfo) Walk() { // Create a buffer var b bytes.Buffer w := binutil.Writer{W: &b} // Write to the buffer binutil.Walk(vi.Structure, func(v reflect.Value, path string) error { if binutil.Plain(v.Kind()) { w.WriteLE(v.Interface()) } return nil }) vi.Buffer = b }
func writeCoffTo(w io.WriteCloser, coff *coff.Coff) error { bw := binutil.Writer{W: w} // write the resulting file to disk binutil.Walk(coff, func(v reflect.Value, path string) error { if binutil.Plain(v.Kind()) { bw.WriteLE(v.Interface()) return nil } vv, ok := v.Interface().(binutil.SizedReader) if ok { bw.WriteFromSized(vv) return binutil.WALK_SKIP } return nil }) err := bw.Err if closeErr := w.Close(); closeErr != nil && err == nil { err = closeErr } return err }