Skip to content

Commit

Permalink
PNG packing (#3)
Browse files Browse the repository at this point in the history
* Add PNG packing.

* Fix PNG unparse error message.
  • Loading branch information
Duosion authored Aug 5, 2024
1 parent 7f89b4b commit ed4b97d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/wf/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func NewPacker(config *PackerConfig) (*Packer, error) {
parsers := []parser{
// &amf3Parser{ext: ".action.dsl"},
// &esdlParser{&amf3Parser{ext: ".esdl"}},
&pngParser{},
&orderedmapParser{}, // needs to be last because of ambiguous file extension
}

Expand Down
11 changes: 10 additions & 1 deletion pkg/wf/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,16 @@ func (*pngParser) matchDest(dest string, config *PackerConfig) (string, bool) {
}

func (*pngParser) unparse(raw []byte, config *PackerConfig) ([]byte, error) {
return nil, fmt.Errorf("unparse pngParser: not implemented")
// P N G
if raw[1] != 0x50 || raw[2] != 0x4e || raw[3] != 0x47 {
return nil, fmt.Errorf("pngUnparser: png header mismatch, expected: 504e47, found: %x", hex.EncodeToString(raw[1:4]))
}

raw[1] = 0x70
raw[2] = 0x6e
raw[3] = 0x67

return raw, nil
}

type charPngParser struct {
Expand Down

0 comments on commit ed4b97d

Please sign in to comment.