archive

package
v0.0.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2023 License: AGPL-3.0 Imports: 23 Imported by: 4

Documentation

Overview

Package archive is used to parse a .zip file retrieved by the API.

Here is the content of an archive retried on the tablet as example: 384327f5-133e-49c8-82ff-30aa19f3cfa4.content 384327f5-133e-49c8-82ff-30aa19f3cfa4//0-metadata.json 384327f5-133e-49c8-82ff-30aa19f3cfa4//0.rm 384327f5-133e-49c8-82ff-30aa19f3cfa4.pagedata 384327f5-133e-49c8-82ff-30aa19f3cfa4.thumbnails/0.jpg

As the .zip file from remarkable is simply a normal .zip file containing specific file formats, this package is a helper to read and write zip files with the correct format expected by the tablet.

At the core of this archive package, we have the Zip struct that is defined and that represents a Remarkable zip file. Then it provides a Zip.Read() method to unmarshal data from an io.Reader into a Zip struct and a Zip.Write() method to marshal a Zip struct into a io.Writer.

In order to correctly use this package, you will have to understand the format of a Remarkable zip file, and the format of the files that it contains.

You can find some help about the format at the following URL: https://remarkablewiki.com/tech/filesystem

You can also display the go documentation of public structs of this package to have more information. This will be completed in the future hopefully to have a precise overall documentation directly held in this Golang package.

Note that the binary format ".rm" holding the drawing contained in a zip has a dedicated golang package and is not decoded/encoded from the archive package. See encoding/rm in this repository.

To have a more concrete example, see the test files of this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateContent added in v0.0.16

func CreateContent(id, ext, fpath string, pageIds []string) (fileName, filePath string, err error)

func CreateMetadata added in v0.0.16

func CreateMetadata(id, name, parent, colType, fpath string) (fileName string, filePath string, err error)

func CreateZipDirectory added in v0.0.11

func CreateZipDirectory(id string) (string, error)

func CreateZipDocument added in v0.0.11

func CreateZipDocument(id, srcPath string) (zipPath string, err error)

func FixMetadata added in v0.0.16

func FixMetadata(parentId, name, path string) error

FixMetadata fixes the metadata with the new parent and filename

func GetIdFromZip added in v0.0.11

func GetIdFromZip(srcPath string) (id string, err error)

GetIdFromZip tries to get the Document UUID from an archive

func UnixTimestamp added in v0.0.21

func UnixTimestamp() string

Types

type Content added in v0.0.6

type Content struct {
	DummyDocument bool          `json:"dummyDocument"`
	ExtraMetadata ExtraMetadata `json:"extraMetadata"`

	// FileType is "pdf", "epub" or empty for a simple note
	FileType       string `json:"fileType"`
	FontName       string `json:"fontName"`
	LastOpenedPage int    `json:"lastOpenedPage"`
	LineHeight     int    `json:"lineHeight"`
	Margins        int    `json:"margins"`
	// Orientation can take "portrait" or "landscape".
	Orientation string `json:"orientation"`
	PageCount   int    `json:"pageCount"`
	// Pages is a list of page IDs
	Pages          []string `json:"pages"`
	Tags           []string `json:"pageTags"`
	RedirectionMap []int    `json:"redirectionPageMap"`
	TextScale      int      `json:"textScale"`

	Transform Transform `json:"transform"`
}

Content represents the structure of a .content json file.

type DocumentFiles added in v0.0.18

type DocumentFiles struct {
	Files []NamePath
}

func Prepare added in v0.0.16

func Prepare(name, parentId, sourceDocPath, ext, tmpDir string) (files *DocumentFiles, id string, err error)

Prepare prepares a file for uploading (creates needed temp files or unpacks a zip)

func Unpack added in v0.0.16

func Unpack(src, dest string) (id string, files *DocumentFiles, metadataPath string, err error)

Unpack unpacks a rmapi .zip file

func (*DocumentFiles) AddMap added in v0.0.18

func (d *DocumentFiles) AddMap(name, filepath string)

type ExtraMetadata added in v0.0.6

type ExtraMetadata struct {
	LastBrushColor           string `json:"LastBrushColor"`
	LastBrushThicknessScale  string `json:"LastBrushThicknessScale"`
	LastColor                string `json:"LastColor"`
	LastEraserThicknessScale string `json:"LastEraserThicknessScale"`
	LastEraserTool           string `json:"LastEraserTool"`
	LastPen                  string `json:"LastPen"`
	LastPenColor             string `json:"LastPenColor"`
	LastPenThicknessScale    string `json:"LastPenThicknessScale"`
	LastPencil               string `json:"LastPencil"`
	LastPencilColor          string `json:"LastPencilColor"`
	LastPencilThicknessScale string `json:"LastPencilThicknessScale"`
	LastTool                 string `json:"LastTool"`
	ThicknessScale           string `json:"ThicknessScale"`
	LastFinelinerv2Size      string `json:"LastFinelinerv2Size"`
}

ExtraMetadata is a struct contained into a Content struct.

type Layer added in v0.0.6

type Layer struct {
	Name string `json:"name"`
}

Layers is a struct contained into a Metadata struct.

type Metadata added in v0.0.6

type Metadata struct {
	Layers []Layer `json:"layers"`
}

Metadata represents the structure of a .metadata json file associated to a page.

type MetadataFile added in v0.0.16

type MetadataFile struct {
	DocName        string `json:"visibleName"`
	CollectionType string `json:"type"`
	Parent         string `json:"parent"`
	//LastModified in milliseconds
	LastModified     string `json:"lastModified"`
	LastOpened       string `json:"lastOpened"`
	LastOpenedPage   int    `json:"lastOpenedPage"`
	Version          int    `json:"version"`
	Pinned           bool   `json:"pinned"`
	Synced           bool   `json:"synced"`
	Modified         bool   `json:"modified"`
	Deleted          bool   `json:"deleted"`
	MetadataModified bool   `json:"metadatamodified"`
}

MetadataFile content

type NamePath added in v0.0.18

type NamePath struct {
	Name string
	Path string
}

type Page

type Page struct {
	// Data is the rm binary encoded file representing the drawn content
	Data *rm.Rm
	// Metadata is a json file containing information about layers
	Metadata Metadata
	// Thumbnail is a small image of the overall page
	Thumbnail []byte
	// Pagedata contains the name of the selected background template
	Pagedata string
	// page number of the underlying document
	DocPage int
}

A Page represents a note page.

type Transform added in v0.0.6

type Transform struct {
	M11 float32 `json:"m11"`
	M12 float32 `json:"m12"`
	M13 float32 `json:"m13"`
	M21 float32 `json:"m21"`
	M22 float32 `json:"m22"`
	M23 float32 `json:"m23"`
	M31 float32 `json:"m31"`
	M32 float32 `json:"m32"`
	M33 float32 `json:"m33"`
}

Transform is a struct contained into a Content struct.

type Zip added in v0.0.6

type Zip struct {
	Content Content
	Pages   []Page
	Payload []byte
	UUID    string
	// contains filtered or unexported fields
}

Zip represents an entire Remarkable archive file.

func NewZip added in v0.0.6

func NewZip() *Zip

NewZip creates a File with sane defaults.

func (*Zip) Read added in v0.0.6

func (z *Zip) Read(r io.ReaderAt, size int64) error

Read fills a Zip parsing a Remarkable archive file.

func (*Zip) Write added in v0.0.6

func (z *Zip) Write(w io.Writer) error

Write writes an archive file from a Zip struct. It automatically generates a uuid if not already defined in the struct.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL