mirror of
https://github.com/Belphemur/CBZOptimizer.git
synced 2025-10-14 12:38:50 +02:00
perf: use deflate for compressable files
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/belphemur/CBZOptimizer/packer"
|
"github.com/belphemur/CBZOptimizer/packer"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func WriteChapterToCBZ(chapter *packer.Chapter, outputFilePath string) error {
|
func WriteChapterToCBZ(chapter *packer.Chapter, outputFilePath string) error {
|
||||||
@@ -36,7 +37,11 @@ func WriteChapterToCBZ(chapter *packer.Chapter, outputFilePath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a new file in the ZIP archive
|
// Create a new file in the ZIP archive
|
||||||
fileWriter, err := zipWriter.Create(fileName)
|
fileWriter, err := zipWriter.CreateHeader(&zip.FileHeader{
|
||||||
|
Name: fileName,
|
||||||
|
Method: zip.Store,
|
||||||
|
Modified: time.Now(),
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create file in .cbz: %w", err)
|
return fmt.Errorf("failed to create file in .cbz: %w", err)
|
||||||
}
|
}
|
||||||
@@ -50,7 +55,11 @@ func WriteChapterToCBZ(chapter *packer.Chapter, outputFilePath string) error {
|
|||||||
|
|
||||||
// Optionally, write the ComicInfo.xml file if present
|
// Optionally, write the ComicInfo.xml file if present
|
||||||
if chapter.ComicInfoXml != "" {
|
if chapter.ComicInfoXml != "" {
|
||||||
comicInfoWriter, err := zipWriter.Create("ComicInfo.xml")
|
comicInfoWriter, err := zipWriter.CreateHeader(&zip.FileHeader{
|
||||||
|
Name: "ComicInfo.xml",
|
||||||
|
Method: zip.Deflate,
|
||||||
|
Modified: time.Now(),
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create ComicInfo.xml in .cbz: %w", err)
|
return fmt.Errorf("failed to create ComicInfo.xml in .cbz: %w", err)
|
||||||
}
|
}
|
||||||
@@ -62,7 +71,11 @@ func WriteChapterToCBZ(chapter *packer.Chapter, outputFilePath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if chapter.IsConverted {
|
if chapter.IsConverted {
|
||||||
convertedWriter, err := zipWriter.Create("Converted.txt")
|
convertedWriter, err := zipWriter.CreateHeader(&zip.FileHeader{
|
||||||
|
Name: "Converted.txt",
|
||||||
|
Method: zip.Deflate,
|
||||||
|
Modified: time.Now(),
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create Converted.txt in .cbz: %w", err)
|
return fmt.Errorf("failed to create Converted.txt in .cbz: %w", err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user