Skip to content

Commit

Permalink
fix RenderFilename (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy authored Oct 25, 2024
1 parent beb2212 commit f96992e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gvc/gvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
_ "image/jpeg"
_ "image/png"
"io"
"os"

"github.com/goccy/go-graphviz/cgraph"
"github.com/goccy/go-graphviz/internal/wasm"
Expand Down Expand Up @@ -84,6 +85,13 @@ func (c *Context) RenderImage(ctx context.Context, g *cgraph.Graph, format strin
}

func (c *Context) RenderFilename(ctx context.Context, g *cgraph.Graph, format, filename string) error {
if _, err := os.Stat(filename); err != nil {
// file does not exist.
// Since gvc.RenderFilename fails if the file doesn't exist, we create it beforehand.
if _, err := os.Create(filename); err != nil {
return fmt.Errorf("failed to create file: %w", err)
}
}
res, err := c.gvc.RenderFilename(ctx, toGraphWasm(g), format, filename)
if err != nil {
return err
Expand Down

0 comments on commit f96992e

Please sign in to comment.