Skip to content

Commit

Permalink
Gzip binary
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2brain committed Mar 12, 2024
1 parent 1d4e203 commit c257991
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
16 changes: 14 additions & 2 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package heic

import (
"bytes"
"compress/gzip"
"context"
_ "embed"
"fmt"
Expand All @@ -16,7 +17,7 @@ import (
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
)

//go:embed lib/heif.wasm
//go:embed lib/heif.wasm.gz
var heifWasm []byte

func decode(r io.Reader, configOnly bool) (image.Image, image.Config, error) {
Expand Down Expand Up @@ -153,7 +154,18 @@ func initialize() {
ctx := context.Background()
rt := wazero.NewRuntime(ctx)

compiled, err := rt.CompileModule(ctx, heifWasm)
r, err := gzip.NewReader(bytes.NewReader(heifWasm))
if err != nil {
panic(err)
}

var data bytes.Buffer
_, err = data.ReadFrom(r)
if err != nil {
panic(err)
}

compiled, err := rt.CompileModule(ctx, data.Bytes())
if err != nil {
panic(err)
}
Expand Down
7 changes: 3 additions & 4 deletions lib/heif.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ int decode(uint8_t *heic_in, int heic_in_size, int config_only, uint32_t *width,
return 1;
}

void __cxa_allocate_exception() {
abort();
int __cxa_allocate_exception(int a) {
return 0;
}

void __cxa_throw() {
abort();
void __cxa_throw(int a, int b, int c) {
}
Binary file removed lib/heif.wasm
Binary file not shown.
Binary file added lib/heif.wasm.gz
Binary file not shown.

0 comments on commit c257991

Please sign in to comment.