diff --git a/rm2pdf.go b/rm2pdf.go index dd766c6..ba2befc 100644 --- a/rm2pdf.go +++ b/rm2pdf.go @@ -2,6 +2,7 @@ package rm2pdf import ( "archive/zip" + "bytes" "io" "io/ioutil" "strings" @@ -37,20 +38,9 @@ func RenderRmFile(input io.ReadCloser, output io.Writer) error { return nil } -// RenderRmNotebook converts an entire Remarkable Notebook -// and renders it as a multiple-page PDF. -// -// input is the name of the Notebook, in zip, format, to open. -// -// output is where the PDF is written. -func RenderRmNotebook(input string, output io.Writer) error { - reader, err := zip.OpenReader(input) - defer reader.Close() - - if err != nil { - return err - } - +// RenderRmNotebookFromBytes is identical to RenderRmNotebook, but +// takes a *zip.Reader as input. +func RenderRmNotebookFromZip(reader *zip.Reader, output io.Writer) error { pdf := gofpdf.New("P", "in", "letter", "") for _, file := range reader.File { @@ -85,3 +75,33 @@ func RenderRmNotebook(input string, output io.Writer) error { return nil } + +// RenderRmNotebookFromBytes is identical to RenderRmNotebook, but +// takes a byte array of the zip file as input. +func RenderRmNotebookFromBytes(input []byte, output io.Writer) error { + inputReader := bytes.NewReader(input) + reader, err := zip.NewReader(inputReader, inputReader.Size()) + + if err != nil { + return err + } + + return RenderRmNotebookFromZip(reader, output) +} + +// RenderRmNotebook converts an entire Remarkable Notebook +// and renders it as a multiple-page PDF. +// +// input is the name of the Notebook, in zip, format, to open. +// +// output is where the PDF is written. +func RenderRmNotebook(input string, output io.Writer) error { + reader, err := zip.OpenReader(input) + defer reader.Close() + + if err != nil { + return err + } + + return RenderRmNotebookFromZip(&reader.Reader, output) +}