From eb3c1c2e068e5e92848a60967be685ec3d85d0f0 Mon Sep 17 00:00:00 2001 From: Roman Mohr Date: Tue, 27 Oct 2020 14:36:00 +0100 Subject: [PATCH 1/2] Expose method to return CpioStream for RPM contents This lets us stream the contents as a CPIO archive in lieu of having to get at the raw io.Reader to do this. Signed-off-by: Michael Kelly --- rpmutils.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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. From 2c4aa135cbfee6247905d845493d572d20668377 Mon Sep 17 00:00:00 2001 From: Roman Mohr Date: Tue, 15 Dec 2020 13:39:07 +0100 Subject: [PATCH 2/2] Add CpioEntry methods to interact with payload This lets us do some simple interactions with the entry payload (read, copy between streams, see if we have a payload) without needlessly exposing the internal guts. Signed-off-by: Michael Kelly --- cpio/cpio.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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{