From eb13d25d4eec5a0fffcb76e4abedf9097d0a0ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20Einarson?= Date: Fri, 10 May 2024 13:02:33 +0200 Subject: [PATCH] chore: remove obsolete ioutil for Go version >= 1.16 --- CHANGELOG.md | 5 +++++ avc/slice_test.go | 6 +++--- bits/reader.go | 3 +-- bits/writer_benchmark_test.go | 6 +++--- cmd/mp4ff-decrypt/decrypt_test.go | 5 ++--- cmd/mp4ff-encrypt/main.go | 3 +-- cmd/mp4ff-nallister/main.go | 3 +-- cmd/mp4ff-pslister/main.go | 3 +-- examples/combine-segs/main.go | 5 ++--- examples/multitrack/helpers_test.go | 3 +-- examples/multitrack/multitrack_test.go | 3 +-- hevc/slice_test.go | 4 ++-- mp4/benchmarks_srw_test.go | 8 ++++---- mp4/benchmarks_test.go | 8 ++++---- mp4/boxsr_test.go | 4 ++-- mp4/dac3.go | 3 +-- mp4/dec3.go | 3 +-- mp4/file_test.go | 3 +-- mp4/infodumper_test.go | 4 ++-- mp4/initsegment_test.go | 7 +++---- mp4/mediasegment_test.go | 11 +++++------ 21 files changed, 46 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58861abb..6a28437b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- minimum Go version 1.16. +- ioutil imports replaced by io and os imports + ### Fixed - support for parsing of hierarchical sidx boxes diff --git a/avc/slice_test.go b/avc/slice_test.go index 31870449..fc6d41df 100644 --- a/avc/slice_test.go +++ b/avc/slice_test.go @@ -2,7 +2,7 @@ package avc import ( "encoding/hex" - "io/ioutil" + "os" "testing" "github.com/go-test/deep" @@ -30,7 +30,7 @@ func TestParseSliceHeader_BlackFrame(t *testing.T) { SliceBetaOffsetDiv2: -3, Size: 7, } - data, err := ioutil.ReadFile("testdata/blackframe.264") + data, err := os.ReadFile("testdata/blackframe.264") if err != nil { t.Error(err) } @@ -71,7 +71,7 @@ func TestParseSliceHeader_TwoFrames(t *testing.T) { Size: 5, NumRefIdxActiveOverrideFlag: true, RefPicListModificationL0Flag: true, } - data, err := ioutil.ReadFile("testdata/two-frames.264") + data, err := os.ReadFile("testdata/two-frames.264") if err != nil { t.Error(err) } diff --git a/bits/reader.go b/bits/reader.go index a9cf4af7..6a43a5f1 100644 --- a/bits/reader.go +++ b/bits/reader.go @@ -4,7 +4,6 @@ import ( "encoding/binary" "fmt" "io" - "io/ioutil" ) // Reader is a bit reader that stops reading at first error and stores it. @@ -85,7 +84,7 @@ func (r *Reader) ReadRemainingBytes() []byte { r.err = fmt.Errorf("%d bit instead of byte alignment when reading remaining bytes", r.n) return nil } - rest, err := ioutil.ReadAll(r.rd) + rest, err := io.ReadAll(r.rd) if err != nil { r.err = err return nil diff --git a/bits/writer_benchmark_test.go b/bits/writer_benchmark_test.go index 3cb182df..ba9dcdfb 100644 --- a/bits/writer_benchmark_test.go +++ b/bits/writer_benchmark_test.go @@ -1,14 +1,14 @@ package bits_test import ( - "io/ioutil" + "io" "testing" "github.com/Eyevinn/mp4ff/bits" ) func BenchmarkWrite(b *testing.B) { - writer := bits.NewWriter(ioutil.Discard) + writer := bits.NewWriter(io.Discard) b.ResetTimer() for i := 0; i < b.N; i++ { writer.Write(0xff, 8) @@ -20,7 +20,7 @@ func BenchmarkWrite(b *testing.B) { } func BenchmarkEbspWrite(b *testing.B) { - writer := bits.NewEBSPWriter(ioutil.Discard) + writer := bits.NewEBSPWriter(io.Discard) b.ResetTimer() for i := 0; i < b.N; i++ { writer.Write(0xff, 8) diff --git a/cmd/mp4ff-decrypt/decrypt_test.go b/cmd/mp4ff-decrypt/decrypt_test.go index f59c009f..d18bc266 100644 --- a/cmd/mp4ff-decrypt/decrypt_test.go +++ b/cmd/mp4ff-decrypt/decrypt_test.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "io/ioutil" "os" "testing" @@ -68,7 +67,7 @@ func TestDecryptFiles(t *testing.T) { if err != nil { t.Error(err) } - expectedOut, err := ioutil.ReadFile(tc.expectedOutFile) + expectedOut, err := os.ReadFile(tc.expectedOutFile) if err != nil { t.Error(err) } @@ -83,7 +82,7 @@ func TestDecryptFiles(t *testing.T) { func BenchmarkDecodeCenc(b *testing.B) { inFile := "../../mp4/testdata/prog_8s_enc_dashinit.mp4" hexKey := "63cb5f7184dd4b689a5c5ff11ee6a328" - raw, err := ioutil.ReadFile(inFile) + raw, err := os.ReadFile(inFile) if err != nil { b.Error(err) } diff --git a/cmd/mp4ff-encrypt/main.go b/cmd/mp4ff-encrypt/main.go index dac8c063..8fdd4e90 100644 --- a/cmd/mp4ff-encrypt/main.go +++ b/cmd/mp4ff-encrypt/main.go @@ -6,7 +6,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "os" "strings" @@ -99,7 +98,7 @@ func main() { var psshData []byte if opts.psshFile != "" { - psshData, err = ioutil.ReadFile(opts.psshFile) + psshData, err = os.ReadFile(opts.psshFile) if err != nil { log.Fatalf("could not read pssh data from file: %s", err) } diff --git a/cmd/mp4ff-nallister/main.go b/cmd/mp4ff-nallister/main.go index 25895073..5fc9658e 100644 --- a/cmd/mp4ff-nallister/main.go +++ b/cmd/mp4ff-nallister/main.go @@ -6,7 +6,6 @@ import ( "encoding/hex" "flag" "fmt" - "io/ioutil" "log" "os" "strings" @@ -59,7 +58,7 @@ func main() { } // First try to handle Annex B file if *annexB { - data, err := ioutil.ReadFile(inFilePath) + data, err := os.ReadFile(inFilePath) if err != nil { log.Fatal(err) } diff --git a/cmd/mp4ff-pslister/main.go b/cmd/mp4ff-pslister/main.go index 9883f01c..accbbed4 100644 --- a/cmd/mp4ff-pslister/main.go +++ b/cmd/mp4ff-pslister/main.go @@ -9,7 +9,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "os" "strings" @@ -178,7 +177,7 @@ func run(inFile, vpsHex, spsHex, ppsHex, codec string, version, verbose bool) er } func getNalusFromBytestream(f io.Reader) ([][]byte, error) { - byteStream, err := ioutil.ReadAll(f) + byteStream, err := io.ReadAll(f) if err != nil { log.Fatalln(err) } diff --git a/examples/combine-segs/main.go b/examples/combine-segs/main.go index f27b1a9d..c5f4105a 100644 --- a/examples/combine-segs/main.go +++ b/examples/combine-segs/main.go @@ -3,7 +3,6 @@ package main import ( "fmt" "io" - "io/ioutil" "os" "github.com/Eyevinn/mp4ff/bits" @@ -40,7 +39,7 @@ func main() { func combineInitSegments(files []string, newTrackIDs []uint32) (*mp4.InitSegment, error) { var combinedInit *mp4.InitSegment for i := 0; i < len(files); i++ { - data, err := ioutil.ReadFile(files[i]) + data, err := os.ReadFile(files[i]) if err != nil { return nil, fmt.Errorf("failed to read init segment: %w", err) } @@ -78,7 +77,7 @@ func combineMediaSegments(files []string, newTrackIDs []uint32) (*mp4.MediaSegme var combinedSeg *mp4.MediaSegment var outFrag *mp4.Fragment for i := 0; i < len(files); i++ { - data, err := ioutil.ReadFile(files[i]) + data, err := os.ReadFile(files[i]) if err != nil { return nil, fmt.Errorf("failed to read media segment: %w", err) } diff --git a/examples/multitrack/helpers_test.go b/examples/multitrack/helpers_test.go index 6a4738c7..3b79e07e 100644 --- a/examples/multitrack/helpers_test.go +++ b/examples/multitrack/helpers_test.go @@ -4,7 +4,6 @@ import ( "bytes" "flag" "fmt" - "io/ioutil" "os" "strings" "testing" @@ -46,7 +45,7 @@ func compareOrUpdateGolden(t *testing.T, genData []byte, path string) (err error } // Compare with golden dump file - golden, err := ioutil.ReadFile(path) + golden, err := os.ReadFile(path) if err != nil { t.Error(err) } diff --git a/examples/multitrack/multitrack_test.go b/examples/multitrack/multitrack_test.go index 079007c3..86edc9ce 100644 --- a/examples/multitrack/multitrack_test.go +++ b/examples/multitrack/multitrack_test.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "io/ioutil" "os" "testing" @@ -87,7 +86,7 @@ func TestGetMultiTrackSamples(t *testing.T) { t.Error(err) } - inFileRaw, err := ioutil.ReadFile(filePath) + inFileRaw, err := os.ReadFile(filePath) if err != nil { t.Error(err) } diff --git a/hevc/slice_test.go b/hevc/slice_test.go index 2043b752..3a0ed0d0 100644 --- a/hevc/slice_test.go +++ b/hevc/slice_test.go @@ -1,7 +1,7 @@ package hevc import ( - "io/ioutil" + "os" "testing" "github.com/Eyevinn/mp4ff/avc" @@ -82,7 +82,7 @@ func TestParseSliceHeader(t *testing.T) { Size: 10, }, } - data, err := ioutil.ReadFile("testdata/blackframe.265") + data, err := os.ReadFile("testdata/blackframe.265") if err != nil { t.Error(err) } diff --git a/mp4/benchmarks_srw_test.go b/mp4/benchmarks_srw_test.go index c0bf6ee5..e3d64c9a 100644 --- a/mp4/benchmarks_srw_test.go +++ b/mp4/benchmarks_srw_test.go @@ -2,7 +2,7 @@ package mp4 import ( "bytes" - "io/ioutil" + "os" "testing" "github.com/Eyevinn/mp4ff/bits" @@ -14,7 +14,7 @@ func TestDecodEncodeFileSRW(t *testing.T) { "prog_8s.mp4", } for _, testFile := range testFiles { - raw, err := ioutil.ReadFile("testdata/" + testFile) + raw, err := os.ReadFile("testdata/" + testFile) if err != nil { t.Error(err) } @@ -44,7 +44,7 @@ func BenchmarkDecodeFileSR(b *testing.B) { "prog_8s.mp4", } for _, testFile := range testFiles { - raw, _ := ioutil.ReadFile("testdata/" + testFile) + raw, _ := os.ReadFile("testdata/" + testFile) b.Run(testFile, func(b *testing.B) { for i := 0; i < b.N; i++ { sr := bits.NewFixedSliceReader(raw) @@ -60,7 +60,7 @@ func BenchmarkEncodeFileSW(b *testing.B) { "prog_8s.mp4", } for _, testFile := range testFiles { - raw, _ := ioutil.ReadFile("testdata/" + testFile) + raw, _ := os.ReadFile("testdata/" + testFile) inBuf := bytes.NewBuffer(raw) decFile, _ := DecodeFile(inBuf) rawOut := make([]byte, len(raw)) diff --git a/mp4/benchmarks_test.go b/mp4/benchmarks_test.go index b7a287d8..85527e85 100644 --- a/mp4/benchmarks_test.go +++ b/mp4/benchmarks_test.go @@ -2,7 +2,7 @@ package mp4 import ( "bytes" - "io/ioutil" + "os" "testing" ) @@ -12,7 +12,7 @@ func TestDecodEncodeFile(t *testing.T) { "prog_8s.mp4", } for _, testFile := range testFiles { - raw, err := ioutil.ReadFile("testdata/" + testFile) + raw, err := os.ReadFile("testdata/" + testFile) if err != nil { t.Error(err) } @@ -43,7 +43,7 @@ func BenchmarkDecodeFile(b *testing.B) { "prog_8s.mp4", } for _, testFile := range testFiles { - raw, _ := ioutil.ReadFile("testdata/" + testFile) + raw, _ := os.ReadFile("testdata/" + testFile) b.Run(testFile, func(b *testing.B) { for i := 0; i < b.N; i++ { buf := bytes.NewBuffer(raw) @@ -59,7 +59,7 @@ func BenchmarkEncodeFile(b *testing.B) { "prog_8s.mp4", } for _, testFile := range testFiles { - raw, _ := ioutil.ReadFile("testdata/" + testFile) + raw, _ := os.ReadFile("testdata/" + testFile) inBuf := bytes.NewBuffer(raw) decFile, _ := DecodeFile(inBuf) rawOut := make([]byte, 0, len(raw)) diff --git a/mp4/boxsr_test.go b/mp4/boxsr_test.go index 1b784e0e..6a1f2095 100644 --- a/mp4/boxsr_test.go +++ b/mp4/boxsr_test.go @@ -2,7 +2,7 @@ package mp4 import ( "bytes" - "io/ioutil" + "os" "testing" "github.com/Eyevinn/mp4ff/bits" @@ -17,7 +17,7 @@ func TestDecodeEncodeSRW(t *testing.T) { } for _, testFile := range testFiles { - inData, err := ioutil.ReadFile(testFile) + inData, err := os.ReadFile(testFile) if err != nil { t.Error(err) } diff --git a/mp4/dac3.go b/mp4/dac3.go index b442be5e..f700e669 100644 --- a/mp4/dac3.go +++ b/mp4/dac3.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "strings" "github.com/Eyevinn/mp4ff/bits" @@ -62,7 +61,7 @@ type Dac3Box struct { // DecodeDac3 - box-specific decode func DecodeDac3(hdr BoxHeader, startPos uint64, r io.Reader) (Box, error) { - data, err := ioutil.ReadAll(r) + data, err := io.ReadAll(r) if err != nil { return nil, err } diff --git a/mp4/dec3.go b/mp4/dec3.go index 5d124f49..2a0f87e2 100644 --- a/mp4/dec3.go +++ b/mp4/dec3.go @@ -3,7 +3,6 @@ package mp4 import ( "bytes" "io" - "io/ioutil" "strings" "github.com/Eyevinn/mp4ff/bits" @@ -67,7 +66,7 @@ type EC3Sub struct { // DecodeDec3 - box-specific decode func DecodeDec3(hdr BoxHeader, startPos uint64, r io.Reader) (Box, error) { - data, err := ioutil.ReadAll(r) + data, err := io.ReadAll(r) if err != nil { return nil, err } diff --git a/mp4/file_test.go b/mp4/file_test.go index 01b964cb..16be1576 100644 --- a/mp4/file_test.go +++ b/mp4/file_test.go @@ -2,7 +2,6 @@ package mp4 import ( "bytes" - "io/ioutil" "os" "testing" @@ -124,7 +123,7 @@ func TestDecodeEncode(t *testing.T) { testFiles := []string{"./testdata/prog_8s.mp4", "./testdata/multi_sidx_segment.m4s"} for _, testFile := range testFiles { - rawInput, err := ioutil.ReadFile("./testdata/prog_8s.mp4") + rawInput, err := os.ReadFile("./testdata/prog_8s.mp4") if err != nil { t.Error(err) } diff --git a/mp4/infodumper_test.go b/mp4/infodumper_test.go index 01bf92b1..d32c1d89 100644 --- a/mp4/infodumper_test.go +++ b/mp4/infodumper_test.go @@ -3,7 +3,7 @@ package mp4 import ( "bytes" "fmt" - "io/ioutil" + "os" "strings" "testing" @@ -29,7 +29,7 @@ func compareOrUpdateInfo(t *testing.T, b Informer, path string) error { } // Compare with golden dump file - golden, err := ioutil.ReadFile(path) + golden, err := os.ReadFile(path) if err != nil { t.Error(err) } diff --git a/mp4/initsegment_test.go b/mp4/initsegment_test.go index e0ac6369..8c603ee1 100644 --- a/mp4/initsegment_test.go +++ b/mp4/initsegment_test.go @@ -5,7 +5,6 @@ import ( "encoding/hex" "fmt" "io" - "io/ioutil" "os" "testing" @@ -88,7 +87,7 @@ func TestMoovParsingWithBtrt(t *testing.T) { if err != nil { t.Error(err) } - initFileBytes, err := ioutil.ReadFile(initFile) + initFileBytes, err := os.ReadFile(initFile) if err != nil { t.Error(err) } @@ -121,7 +120,7 @@ func TestMoovWithCenc(t *testing.T) { if err != nil { t.Error(err) } - initFileBytes, err := ioutil.ReadFile(initFile) + initFileBytes, err := os.ReadFile(initFile) if err != nil { t.Error(err) } @@ -196,7 +195,7 @@ func TestGenerateInitSegment(t *testing.T) { return } - golden, err := ioutil.ReadFile(goldenAssetPath) + golden, err := os.ReadFile(goldenAssetPath) if err != nil { t.Error(err) } diff --git a/mp4/mediasegment_test.go b/mp4/mediasegment_test.go index 6a02c5a9..c0b9f9ad 100644 --- a/mp4/mediasegment_test.go +++ b/mp4/mediasegment_test.go @@ -3,7 +3,6 @@ package mp4 import ( "bytes" "io" - "io/ioutil" "os" "testing" @@ -42,7 +41,7 @@ func TestMediaSegmentFragmentation(t *testing.T) { t.Error(err) } - inSeg, err := ioutil.ReadFile(inFile) + inSeg, err := os.ReadFile(inFile) if err != nil { t.Fatal(err) } @@ -92,7 +91,7 @@ func TestMediaSegmentFragmentation(t *testing.T) { t.Error(err) } } else { - goldenFrag, err := ioutil.ReadFile(goldenFragPath) + goldenFrag, err := os.ReadFile(goldenFragPath) if err != nil { t.Error(err) } @@ -125,7 +124,7 @@ func TestDecodeEncodeNoOptimize(t *testing.T) { inFile := "testdata/1.m4s" - data, err := ioutil.ReadFile(inFile) + data, err := os.ReadFile(inFile) if err != nil { t.Fatal(err) } @@ -174,7 +173,7 @@ func TestMoofEncrypted(t *testing.T) { t.Error(err) } - inSeg, err := ioutil.ReadFile(inFile) + inSeg, err := os.ReadFile(inFile) if err != nil { t.Fatal(err) } @@ -197,7 +196,7 @@ func TestMoofEncrypted(t *testing.T) { } func TestDecodeEncodeCencFragmentedFile(t *testing.T) { - inData, err := ioutil.ReadFile("testdata/prog_8s_enc_dashinit.mp4") + inData, err := os.ReadFile("testdata/prog_8s_enc_dashinit.mp4") if err != nil { t.Fatal(err) }