Skip to content

Commit

Permalink
fix: do not export newBytesFileWithPath
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Aug 21, 2023
1 parent bfffd83 commit dfc4949
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 10 additions & 5 deletions files/multifilereader_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package files

import (
"bytes"
"io"
"mime/multipart"
"testing"
Expand All @@ -10,6 +11,10 @@ import (

var text = "Some text! :)"

func newBytesFileWithPath(abspath string, b []byte) File {
return &ReaderFile{abspath, bytesReaderCloser{bytes.NewReader(b)}, nil, int64(len(b))}
}

func makeMultiFileReader(t *testing.T, binaryFileName, rawAbsPath bool) (string, *MultiFileReader) {
var (
filename string
Expand All @@ -18,19 +23,19 @@ func makeMultiFileReader(t *testing.T, binaryFileName, rawAbsPath bool) (string,

if binaryFileName {
filename = "bad\x7fname.txt"
file = NewBytesFileWithPath("/my/path/boop/bad\x7fname.txt", []byte("bloop"))
file = newBytesFileWithPath("/my/path/boop/bad\x7fname.txt", []byte("bloop"))
} else {
filename = "résumé🥳.txt"
file = NewBytesFileWithPath("/my/path/boop/résumé🥳.txt", []byte("bloop"))
file = newBytesFileWithPath("/my/path/boop/résumé🥳.txt", []byte("bloop"))
}

sf := NewMapDirectory(map[string]Node{
"file.txt": NewBytesFileWithPath("/my/path/file.txt", []byte(text)),
"file.txt": newBytesFileWithPath("/my/path/file.txt", []byte(text)),
"boop": NewMapDirectory(map[string]Node{
"a.txt": NewBytesFileWithPath("/my/path/boop/a.txt", []byte("bleep")),
"a.txt": newBytesFileWithPath("/my/path/boop/a.txt", []byte("bleep")),
filename: file,
}),
"beep.txt": NewBytesFileWithPath("/my/path/beep.txt", []byte("beep")),
"beep.txt": newBytesFileWithPath("/my/path/beep.txt", []byte("beep")),
})

return filename, NewMultiFileReader(sf, true, rawAbsPath)
Expand Down
4 changes: 0 additions & 4 deletions files/readerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ func NewBytesFile(b []byte) File {
return &ReaderFile{"", bytesReaderCloser{bytes.NewReader(b)}, nil, int64(len(b))}
}

func NewBytesFileWithPath(abspath string, b []byte) File {
return &ReaderFile{abspath, bytesReaderCloser{bytes.NewReader(b)}, nil, int64(len(b))}
}

// TODO: Is this the best way to fix this bug?
// The bug is we want to be an io.ReadSeekCloser, but bytes.NewReader only gives a io.ReadSeeker and io.NopCloser
// effectively removes the io.Seeker ability from the passed in io.Reader
Expand Down

0 comments on commit dfc4949

Please sign in to comment.