Compare commits

...

2 commits

Author SHA1 Message Date
d11fa31023 fix ytdlp
Some checks failed
docker / build-docker (linux/amd64) (push) Successful in 2m32s
docker / build-docker (linux/arm64) (push) Failing after 3h11m46s
2024-06-20 11:20:53 +03:00
d973e67ea3 fix zip reader 2024-06-20 11:20:43 +03:00
3 changed files with 23 additions and 8 deletions

View file

@ -199,7 +199,7 @@ type Format struct {
ManifestURL *string `json:"manifest_url,omitempty"`
Language *Language `json:"language"`
Preference interface{} `json:"preference"`
Quality *int64 `json:"quality,omitempty"`
Quality *float64 `json:"quality,omitempty"`
HasDRM *bool `json:"has_drm,omitempty"`
SourcePreference *int64 `json:"source_preference,omitempty"`
ASR *int64 `json:"asr"`

View file

@ -239,6 +239,10 @@ func (d *archiveFile) loadMore(ctx context.Context, to int64) error {
if err != nil && err != io.EOF {
return fmt.Errorf("error copying from archive file reader: %w", err)
}
_, err = d.buffer.Seek(d.offset, io.SeekStart)
if err != nil {
return fmt.Errorf("failed to seek to start of the file: %w", err)
}
return nil
}
@ -252,6 +256,7 @@ func (d *archiveFile) Read(ctx context.Context, p []byte) (n int, err error) {
if err != nil && err != io.EOF {
return n, fmt.Errorf("failed to read from buffer: %w", err)
}
d.offset += int64(n)
return n, nil
}
@ -292,12 +297,12 @@ func ZipLoader(ctx context.Context, ctxreader ctxio.ReaderAt, size int64) (map[s
zr, err := zip.NewReader(reader, size)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create zip reader: %w", err)
}
rc, err := zr.File[i].Open()
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to open file in zip archive: %w", err)
}
return rc, nil

View file

@ -4,7 +4,6 @@ import (
"archive/zip"
"bytes"
"context"
"io"
"testing"
"git.kmsign.ru/royalcat/tstor/src/vfs"
@ -59,13 +58,24 @@ func TestZipFilesystem(t *testing.T) {
require.Equal("1.txt", e.Name())
require.NotNil(e)
out := make([]byte, 11)
out := make([]byte, 5)
f, err := zfs.Open(ctx, "/path/to/test/file/1.txt")
require.NoError(err)
n, err := f.Read(ctx, out)
require.Equal(io.EOF, err)
require.Equal(11, n)
require.Equal(fileContent, out)
require.NoError(err)
require.Equal(5, n)
require.Equal([]byte("Hello"), out)
outSpace := make([]byte, 1)
n, err = f.Read(ctx, outSpace)
require.NoError(err)
require.Equal(1, n)
require.Equal([]byte(" "), outSpace)
n, err = f.Read(ctx, out)
require.NoError(err)
require.Equal(5, n)
require.Equal([]byte("World"), out)
}