// FIXME: this should move into the "ar" library itself func addFileToAr(arWriter *ar.Writer, filename string) error { dataF, err := os.Open(filename) if err != nil { return nil } defer dataF.Close() stat, err := dataF.Stat() if err != nil { return err } size := stat.Size() hdr := &ar.Header{ Name: filepath.Base(filename), ModTime: time.Now(), Mode: int64(stat.Mode()), Size: size, } arWriter.WriteHeader(hdr) _, err = io.Copy(arWriter, dataF) // io.Copy() is confused by the fact that a ar file must be even // aligned, so it may return a bigger amounts of bytes written // than requested. This is not a error so we ignore it if err != io.ErrShortWrite { return err } return nil }
func addArFile(now time.Time, w *ar.Writer, name string, body []byte) error { hdr := ar.Header{ Name: name, Size: int64(len(body)), Mode: 0644, ModTime: now, } if err := w.WriteHeader(&hdr); err != nil { return fmt.Errorf("cannot write file header: %v", err) } _, err := w.Write(body) return err }
// FIXME: this should move into the "ar" library itself func addDataToAr(arWriter *ar.Writer, filename string, data []byte) error { size := int64(len(data)) hdr := &ar.Header{ Name: filename, ModTime: time.Now(), Mode: 0644, Size: size, } arWriter.WriteHeader(hdr) _, err := arWriter.Write([]byte(data)) if err != nil { return err } return nil }