Skip to content

Commit

Permalink
update flac errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gcottom committed Mar 31, 2024
1 parent 3ccfdf8 commit 6220de5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 49 deletions.
12 changes: 6 additions & 6 deletions flac/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package flac
import "errors"

var (
ErrorNotVorbisComment = errors.New("Not a vorbis comment metadata block")
ErrorUnexpEof = errors.New("Unexpected end of stream")
ErrorMalformedComment = errors.New("Malformed comment")
ErrorInvalidFieldName = errors.New("Malformed Field Name")
ErrorNotVorbisComment = errors.New("not a vorbis comment metadata block")
ErrorUnexpEof = errors.New("unexpected end of stream")
ErrorMalformedComment = errors.New("malformed comment")
ErrorInvalidFieldName = errors.New("malformed field Name")
// ErrorNotPictureMetadataBlock is returned if the metadata provided is not a picture block.
ErrorNotPictureMetadataBlock = errors.New("Not a picture metadata block")
ErrorNotPictureMetadataBlock = errors.New("not a picture metadata block")
// ErrorUnsupportedMIME is returned if the provided image MIME type is unsupported.
ErrorUnsupportedMIME = errors.New("Unsupported MIME")
ErrorUnsupportedMIME = errors.New("unsupported MIME")
// ErrorNoFLACHeader indicates that "fLaC" marker not found at the beginning of the file
ErrorNoFLACHeader = errors.New("fLaC head incorrect")
// ErrorNoStreamInfo indicates that StreamInfo Metablock not present or is not the first Metablock
Expand Down
3 changes: 1 addition & 2 deletions flac/flacfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package flac
import (
"bytes"
"io"
"io/ioutil"
"os"
)

Expand All @@ -27,7 +26,7 @@ func (c *File) Marshal() []byte {

// Save encapsulates Marshal and save the file to the file system
func (c *File) Save(fn string) error {
return ioutil.WriteFile(fn, c.Marshal(), 0644)
return os.WriteFile(fn, c.Marshal(), 0644)
}

// ParseMetadata accepts a reader to a FLAC stream and consumes only FLAC metadata
Expand Down
36 changes: 0 additions & 36 deletions flac/parsepic.go

This file was deleted.

31 changes: 31 additions & 0 deletions flac/picture.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package flac

import (
"bytes"
"image/jpeg"
"image/png"
)

// PictureType defines the type of this image
Expand Down Expand Up @@ -132,3 +134,32 @@ func ParsePicFromMetaDataBlock(meta MetaDataBlock) (*MetadataBlockPicture, error

return res, nil
}

// ParsePicture decodes the image and inflated the Width, Height, ColorDepth, IndexedColorCount fields. This is called automatically by NewFromImageData
func (c *MetadataBlockPicture) ParsePicture() error {
switch c.MIME {
case "image/jpeg":
img, err := jpeg.Decode(bytes.NewReader(c.ImageData))
if err != nil {
return err
}
c.IndexedColorCount = uint32(0)
size := img.Bounds()
c.Width = uint32(size.Max.X)
c.Height = uint32(size.Max.Y)
c.ColorDepth = uint32(24)
case "image/png":
img, err := png.Decode(bytes.NewReader(c.ImageData))
if err != nil {
return err
}
c.IndexedColorCount = uint32(0)
size := img.Bounds()
c.Width = uint32(size.Max.X)
c.Height = uint32(size.Max.Y)
c.ColorDepth = uint32(32)
default:
return ErrorUnsupportedMIME
}
return nil
}
4 changes: 0 additions & 4 deletions flac/stream.go

This file was deleted.

2 changes: 2 additions & 0 deletions flac/streamdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"io"
)

type FrameData []byte

// StreamInfoBlock represents the undecoded data of StreamInfo block
type StreamInfoBlock struct {
// BlockSizeMin The minimum block size (in samples) used in the stream.
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/abema/go-mp4 v1.2.0
github.com/aler9/writerseeker v1.1.0
github.com/bogem/id3v2/v2 v2.1.4
github.com/orcaman/writerseeker v0.0.0-20200621085525-1d3f536ff85e
github.com/sunfish-shogi/bufseekio v0.1.0
)

Expand Down

0 comments on commit 6220de5

Please sign in to comment.