Skip to content

Commit

Permalink
Fix inside file name for normal saving into merged cbz
Browse files Browse the repository at this point in the history
  • Loading branch information
arimatakao committed Jun 19, 2024
1 parent 52aaa9a commit 11c08e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 1 addition & 3 deletions cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,7 @@ func downloadProcess(

pageIndex := i + 1

insideFilename := fmt.Sprintf("vol%s_ch%s_%d.%s",
chapter.Volume(),
strings.ReplaceAll(chapter.Number(), ".", "_"),
insideFilename := fmt.Sprintf("%d.%s",
pageIndex,
imgExt)
if pageIndex < 10 {
Expand Down
13 changes: 9 additions & 4 deletions filekit/cbz.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"encoding/json"
"encoding/xml"
"fmt"
"io"
"os"
"path/filepath"
Expand All @@ -14,8 +15,9 @@ import (
)

type cbzArchive struct {
buf *bytes.Buffer
writer *zip.Writer
buf *bytes.Buffer
writer *zip.Writer
pageCounter int
}

// fileName without extension
Expand All @@ -25,8 +27,9 @@ func newCBZArchive() (*cbzArchive, error) {
zipWriter := zip.NewWriter(buf)

c := cbzArchive{
buf: buf,
writer: zipWriter,
buf: buf,
writer: zipWriter,
pageCounter: 1,
}

return &c, nil
Expand Down Expand Up @@ -80,6 +83,7 @@ func (c *cbzArchive) WriteOnDiskAndClose(outputDir, outputFileName string,
}

func (c *cbzArchive) AddFile(fileName string, src []byte) error {
fileName = fmt.Sprintf("%d_%s", c.pageCounter, fileName)
buf := bytes.NewBuffer(src)
w, err := c.writer.Create(fileName)
if err != nil {
Expand All @@ -88,5 +92,6 @@ func (c *cbzArchive) AddFile(fileName string, src []byte) error {
if _, err := io.Copy(w, buf); err != nil {
return err
}
c.pageCounter++
return nil
}

0 comments on commit 11c08e9

Please sign in to comment.