Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/backend/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package backend

import (
"bufio"
"context"
"encoding/json"
"fmt"
Expand All @@ -29,6 +30,11 @@ import (
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)

const (
// defaultBufferSize is the default buffer size for reading the blob, default is 4MB.
defaultBufferSize = 4 * 1024 * 1024
)

// Extract extracts the model artifact.
func (b *backend) Extract(ctx context.Context, target string, output string) error {
// parse the repository and tag from the target.
Expand Down Expand Up @@ -60,8 +66,8 @@ func exportModelArtifact(ctx context.Context, store storage.Storage, manifest oc
if err != nil {
return fmt.Errorf("failed to pull the blob from storage: %w", err)
}

defer reader.Close()
bufferedReader := bufio.NewReaderSize(reader, defaultBufferSize)

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

// untar the blob to the target directory.
if err := archiver.Untar(reader, targetDir); err != nil {
if err := archiver.Untar(bufferedReader, targetDir); err != nil {
return fmt.Errorf("failed to untar the blob to output directory: %w", err)
}
}
Expand Down