cbz

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: MIT Imports: 6 Imported by: 0

README

CBZ

Manage your CBZ files with Go.

Features

  • 📘 Create a CBZ file from scratch.

Roadmap

  • (TODO) 📙 Modify a CBZ file metadata (comicinfo.xml)
  • (TODO) 📗 Automatically create metadata from contents (comicinfo.xml)
  • (TODO) 📕 Extract a CBZ file (or just use unzip...?)
  • (TODO) 🖥️ Use as CLI tool. cbz

Usage

Create a CBZ file
package main

import (
	"fmt"
	"log"

	"github.com/fmartingr/go-cbz"
)

func main() {
	comic, err := cbz.New()
	if err != nil {
		log.Fatal(err)
	}

	// Set some metadata
	comic.ComicInfo().Series = "My Comic"
	comic.ComicInfo().Volume = 1

	// Add some pages
	if err := comic.AppendPage(fmt.Sprintf("testdata/page01.jpg", i)); err != nil {
		log.Fatal(err)
	}
	if err := comic.AppendPage(fmt.Sprintf("testdata/page02.jpg", i)); err != nil {
		log.Fatal(err)
	}

	// Save the comic
	if err := comic.Save("my-comic v01.cbz"); err != nil {
		log.Fatal(err)
	}
}

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CBZ

type CBZ struct {
	Info  *comicinfo.ComicInfo
	Pages []Page
	// contains filtered or unexported fields
}

CBZ represents a comic book

func New

func New() (file *CBZ, err error)

New creates a new ComicBook object

func (*CBZ) AppendPage

func (c *CBZ) AppendPage(path string) error

AppendPage adds a page to the comic book

func (*CBZ) ComicInfo

func (c *CBZ) ComicInfo() *comicinfo.ComicInfo

ComicInfo returns the comic info for the comic book

func (*CBZ) Save

func (c *CBZ) Save(path string) error

Save saves the comic book to the path specified

func (*CBZ) SetComicInfo

func (c *CBZ) SetComicInfo(comicInfo *comicinfo.ComicInfo)

SetComicInfo sets the comic info for the comic book

type Compressor

type Compressor interface {
	AddFile(filename string) (io.Writer, error)
	AddFileFromPath(filename, path string) error
	GetFile(filename string) (io.Reader, error)
	Close() error
}

Compressor is the interface that wraps the basic methods for compressing files

func NewZIPCompressor

func NewZIPCompressor(w io.Writer) Compressor

NewZIPCompressor creates a new ZIPCompressor

type Page

type Page struct {
	Number int
	Path   string
}

Page represents a page in a comic book Keep in mind that the pages we store and the pages present in the ComicInfo may be different when opening files, since they may not be present in the ComicInfo file or the ComicInfo file may not be present at all.

type ZIPCompressor

type ZIPCompressor struct {
	// contains filtered or unexported fields
}

ZIPCompressor is a Compressor that uses the ZIP format

func (*ZIPCompressor) AddFile

func (z *ZIPCompressor) AddFile(filename string) (io.Writer, error)

func (*ZIPCompressor) AddFileFromPath

func (z *ZIPCompressor) AddFileFromPath(filename, path string) error

func (*ZIPCompressor) Close

func (z *ZIPCompressor) Close() error

func (*ZIPCompressor) GetFile

func (z *ZIPCompressor) GetFile(filename string) (io.Reader, error)

Jump to

Keyboard shortcuts

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