Skip to content

Commit fc80fae

Browse files
committed
use io.MultiReader instead of manual implementation
1 parent f94eb2e commit fc80fae

File tree

3 files changed

+13
-122
lines changed

3 files changed

+13
-122
lines changed

catalogd/internal/storage/index.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ func (i index) Size() int64 {
5151
return int64(size)
5252
}
5353

54-
func (i index) Get(r io.ReaderAt, schema, packageName, name string) (io.ReadSeeker, bool) {
54+
func (i index) Get(r io.ReaderAt, schema, packageName, name string) (io.Reader, bool) {
5555
sectionSet := i.getSectionSet(schema, packageName, name)
5656

5757
sections := sectionSet.UnsortedList()
5858
slices.SortFunc(sections, func(a, b section) int {
5959
return cmp.Compare(a.offset, b.offset)
6060
})
6161

62-
srs := make([]io.ReadSeeker, 0, len(sections))
62+
srs := make([]io.Reader, 0, len(sections))
6363
for _, s := range sections {
6464
sr := io.NewSectionReader(r, s.offset, s.length)
6565
srs = append(srs, sr)
6666
}
67-
return newMultiReadSeeker(srs...), true
67+
return io.MultiReader(srs...), true
6868
}
6969

7070
func (i *index) getSectionSet(schema, packageName, name string) sets.Set[section] {

catalogd/internal/storage/localdir.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (s *LocalDirV1) handleV1Query(w http.ResponseWriter, r *http.Request) {
236236
httpError(w, fs.ErrNotExist)
237237
return
238238
}
239-
serveJsonLines(w, r, catalogStat.ModTime(), indexReader)
239+
serveJsonLinesQuery(w, indexReader)
240240
}
241241

242242
func (s *LocalDirV1) catalogData(catalog string) (*os.File, os.FileInfo, error) {
@@ -271,6 +271,15 @@ func serveJsonLines(w http.ResponseWriter, r *http.Request, modTime time.Time, r
271271
http.ServeContent(w, r, "", modTime, rs)
272272
}
273273

274+
func serveJsonLinesQuery(w http.ResponseWriter, rs io.Reader) {
275+
w.Header().Add("Content-Type", "application/jsonl")
276+
_, err := io.Copy(w, rs)
277+
if err != nil {
278+
httpError(w, err)
279+
return
280+
}
281+
}
282+
274283
func (s *LocalDirV1) getIndex(catalog string) (*index, error) {
275284
idx, err, _ := s.sf.Do(catalog, func() (interface{}, error) {
276285
indexFile, err := os.Open(catalogIndexFilePath(s.catalogDir(catalog)))

catalogd/internal/storage/multireadseeker.go

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)