refactor: handle errors in createTextChunk and remove commented code
This commit is contained in:
committed by
Grail Finder (aider)
parent
de65f1fc82
commit
753184816c
@@ -18,11 +18,7 @@ const (
|
|||||||
textChunkType = "tEXt"
|
textChunkType = "tEXt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// // PngEmbed holds the key-value pair to embed into the PNG file.
|
// there should be no empty lines inside functions; ai!
|
||||||
// type PngEmbed struct {
|
|
||||||
// Key string
|
|
||||||
// Value string
|
|
||||||
// }
|
|
||||||
|
|
||||||
// WriteToPng embeds the metadata into the specified PNG file and writes the result to outfile.
|
// WriteToPng embeds the metadata into the specified PNG file and writes the result to outfile.
|
||||||
func WriteToPng(metadata *models.CharCardSpec, sourcePath, outfile string) error {
|
func WriteToPng(metadata *models.CharCardSpec, sourcePath, outfile string) error {
|
||||||
@@ -56,7 +52,10 @@ func WriteToPng(metadata *models.CharCardSpec, sourcePath, outfile string) error
|
|||||||
outputBuffer.Write(chunk)
|
outputBuffer.Write(chunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
newChunk := createTextChunk(embedData)
|
newChunk, err := createTextChunk(embedData)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
outputBuffer.Write(newChunk)
|
outputBuffer.Write(newChunk)
|
||||||
outputBuffer.Write(iend)
|
outputBuffer.Write(iend)
|
||||||
|
|
||||||
@@ -124,7 +123,7 @@ func processChunks(data []byte) ([][]byte, []byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// createTextChunk generates a valid tEXt chunk with proper CRC
|
// createTextChunk generates a valid tEXt chunk with proper CRC
|
||||||
func createTextChunk(embed PngEmbed) []byte {
|
func createTextChunk(embed PngEmbed) ([]byte, error) {
|
||||||
content := bytes.NewBuffer(nil)
|
content := bytes.NewBuffer(nil)
|
||||||
content.WriteString(embed.Key)
|
content.WriteString(embed.Key)
|
||||||
content.WriteByte(0) // Null separator
|
content.WriteByte(0) // Null separator
|
||||||
@@ -149,5 +148,5 @@ func createTextChunk(embed PngEmbed) []byte {
|
|||||||
return nil, fmt.Errorf("error writing CRC: %w", err)
|
return nil, fmt.Errorf("error writing CRC: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return chunk.Bytes()
|
return chunk.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user