diff --git a/cpio/cpio.go b/cpio/cpio.go index 8e4bba1..27bdfe2 100644 --- a/cpio/cpio.go +++ b/cpio/cpio.go @@ -46,6 +46,18 @@ type countingReader struct { curPos int64 } +func (ce *CpioEntry) ReadAll() ([]byte, error) { + return io.ReadAll(ce.payload) +} + +func (ce *CpioEntry) Copy(dst io.Writer) (written int64, err error) { + return io.Copy(dst, ce.payload) +} + +func (ce *CpioEntry) HasPayload() bool { + return ce.payload != nil +} + // NewCpioStream starts reading files from a cpio archive func NewCpioStream(stream io.Reader) *CpioStream { return &CpioStream{ diff --git a/rpmutils.go b/rpmutils.go index 5af360a..536ad1b 100644 --- a/rpmutils.go +++ b/rpmutils.go @@ -91,6 +91,16 @@ func (rpm *Rpm) PayloadReaderExtended() (PayloadReader, error) { return newPayloadReader(pld, files), nil } +// CpioStream returns a cpio stream for the RPM payload +func (rpm *Rpm) CpioStream() (*cpio.CpioStream, error) { + pld, err := uncompressRpmPayloadReader(rpm.f, rpm.Header) + if err != nil { + return nil, err + } + + return cpio.NewCpioStream(pld), nil +} + // ReadHeader reads the signature and general headers from a RPM. // // The stream is positioned for reading the compressed payload following the headers.