mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-24 07:42:37 +02:00
add compress raw data
This commit is contained in:
parent
05dd8acc99
commit
2d21ced2fe
@ -66,3 +66,39 @@ func CompressImage(filename string, format string, img image.Image, quality int)
|
||||
cdata.Bytes(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func CompressRaw(filename string, uncompressedData []byte) (Image, error) {
|
||||
var (
|
||||
cdata bytes.Buffer
|
||||
err error
|
||||
)
|
||||
wcdata, err := flate.NewWriter(&cdata, flate.BestCompression)
|
||||
if err != nil {
|
||||
return Image{}, err
|
||||
}
|
||||
|
||||
_, err = wcdata.Write(uncompressedData)
|
||||
if err != nil {
|
||||
return Image{}, err
|
||||
}
|
||||
|
||||
err = wcdata.Close()
|
||||
if err != nil {
|
||||
return Image{}, err
|
||||
}
|
||||
|
||||
t := time.Now()
|
||||
//goland:noinspection GoDeprecation
|
||||
return Image{
|
||||
&zip.FileHeader{
|
||||
Name: filename,
|
||||
CompressedSize64: uint64(cdata.Len()),
|
||||
UncompressedSize64: uint64(len(uncompressedData)),
|
||||
CRC32: crc32.Checksum(uncompressedData, crc32.IEEETable),
|
||||
Method: zip.Deflate,
|
||||
ModifiedTime: uint16(t.Second()/2 + t.Minute()<<5 + t.Hour()<<11),
|
||||
ModifiedDate: uint16(t.Day() + int(t.Month())<<5 + (t.Year()-1980)<<9),
|
||||
},
|
||||
cdata.Bytes(),
|
||||
}, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user