Skip to content

Commit 315dec6

Browse files
authored
feat: add bufferedReader for extract (#86)
Signed-off-by: Gaius <[email protected]>
1 parent 9772029 commit 315dec6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pkg/backend/extract.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package backend
1818

1919
import (
20+
"bufio"
2021
"context"
2122
"encoding/json"
2223
"fmt"
@@ -29,6 +30,11 @@ import (
2930
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3031
)
3132

33+
const (
34+
// defaultBufferSize is the default buffer size for reading the blob, default is 4MB.
35+
defaultBufferSize = 4 * 1024 * 1024
36+
)
37+
3238
// Extract extracts the model artifact.
3339
func (b *backend) Extract(ctx context.Context, target string, output string) error {
3440
// parse the repository and tag from the target.
@@ -60,8 +66,8 @@ func exportModelArtifact(ctx context.Context, store storage.Storage, manifest oc
6066
if err != nil {
6167
return fmt.Errorf("failed to pull the blob from storage: %w", err)
6268
}
63-
6469
defer reader.Close()
70+
bufferedReader := bufio.NewReaderSize(reader, defaultBufferSize)
6571

6672
targetDir := output
6773
// get the original filepath in order to restore the original repo structure.
@@ -71,7 +77,7 @@ func exportModelArtifact(ctx context.Context, store storage.Storage, manifest oc
7177
}
7278

7379
// untar the blob to the target directory.
74-
if err := archiver.Untar(reader, targetDir); err != nil {
80+
if err := archiver.Untar(bufferedReader, targetDir); err != nil {
7581
return fmt.Errorf("failed to untar the blob to output directory: %w", err)
7682
}
7783
}

0 commit comments

Comments
 (0)