av/stream/flac: moved readAll to after loop

This commit is contained in:
saxon 2019-01-21 17:37:16 +10:30
parent 6fda0b3c3f
commit 155134eeed
1 changed files with 4 additions and 8 deletions

View File

@ -25,8 +25,6 @@ func Decode(buf []byte) ([]byte, error) {
enc := wav.NewEncoder(ws, int(stream.Info.SampleRate), int(stream.Info.BitsPerSample), int(stream.Info.NChannels), wavAudioFormat)
defer enc.Close()
var data []int
var out []byte
var d []byte
for {
// Decode FLAC audio samples.
frame, err := stream.ParseNext()
@ -55,12 +53,10 @@ func Decode(buf []byte) ([]byte, error) {
if err := enc.Write(buf); err != nil {
return nil, err
}
d, err = ioutil.ReadAll(ws.Reader())
}
d, err := ioutil.ReadAll(ws.Reader())
if err != nil {
return nil, err
}
out = append(out, d...)
}
return d, nil
}