Skip to content

Commit

Permalink
Implement bytes interface for handling zip files
Browse files Browse the repository at this point in the history
  • Loading branch information
jgoel authored and jgoel committed Dec 24, 2020
1 parent 400b3e2 commit 450200d
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions rm2pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rm2pdf

import (
"archive/zip"
"bytes"
"io"
"io/ioutil"
"strings"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

0 comments on commit 450200d

Please sign in to comment.