Skip to content

Commit

Permalink
fix: update TransferManager downloads to reduce in memory buffering (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWhitehead authored Jul 8, 2024
1 parent a7b83ff commit fc2fd75
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ final class ChunkedDownloadCallable implements Callable<DownloadSegment> {
@Override
public DownloadSegment call() {
long bytesCopied = -1L;
try (ReadChannel rc = storage.reader(originalBlob.getBlobId(), opts)) {
FileChannel wc =
FileChannel.open(destPath, StandardOpenOption.WRITE, StandardOpenOption.CREATE);
try (ReadChannel rc = storage.reader(originalBlob.getBlobId(), opts);
FileChannel wc =
FileChannel.open(destPath, StandardOpenOption.WRITE, StandardOpenOption.CREATE)) {
rc.setChunkSize(0);
rc.seek(startPosition);
rc.limit(endPosition);
wc.position(startPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ public DownloadResult call() {
Path path = TransferManagerUtils.createDestPath(parallelDownloadConfig, originalBlob);
long bytesCopied = -1L;
try (ReadChannel rc =
storage.reader(
BlobId.of(parallelDownloadConfig.getBucketName(), originalBlob.getName()), opts)) {
FileChannel wc =
FileChannel.open(
path,
StandardOpenOption.WRITE,
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING);
storage.reader(
BlobId.of(parallelDownloadConfig.getBucketName(), originalBlob.getName()), opts);
FileChannel wc =
FileChannel.open(
path,
StandardOpenOption.WRITE,
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING)) {
rc.setChunkSize(0);
bytesCopied = ByteStreams.copy(rc, wc);
if (originalBlob.getSize() != null) {
if (bytesCopied != originalBlob.getSize()) {
Expand Down

0 comments on commit fc2fd75

Please sign in to comment.