GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Cannot download gzipped objects larger than ReadChannel chunk size · Issue #982 · googleapis/google-cloud-java

Cannot download gzipped objects larger than ReadChannel chunk size #982

New issue
Copy link
New issue
Copy link
Closed
#1301
Closed
Cannot download gzipped objects larger than ReadChannel chunk size#982
#1301
Copy link
Assignees
mziccard
Labels
api: storageIssues related to the Cloud Storage API.

Description

@clementdenis
clementdenis
opened on May 4, 2016
Issue body actions

I uploaded some big files with gsutil using gzip encoding:
gsutil cp -Z bigfile gs://<bucket_name>/

This code is OK when downloading the file:

    Blob blob = storage.get(bucket, name);
    try (ReadChannel reader = blob.reader()) {
        int fileSize = blob.size().intValue();
        reader.chunkSize(fileSize); //any bigger value is also OK
        ByteStreams.copy(reader, Channels.newChannel(ByteStreams.nullOutputStream()));
    }

This code fails (chunk size is smaller the content size):

    Blob blob = storage.get(bucket, name);
    try (ReadChannel reader = blob.reader()) {
        int fileSize = blob.size().intValue();
        reader.chunkSize(fileSize - 1);
        ByteStreams.copy(reader, Channels.newChannel(ByteStreams.nullOutputStream()));
    }

with this exception

com.google.cloud.storage.StorageException
    at com.google.cloud.storage.spi.DefaultStorageRpc.translate(DefaultStorageRpc.java:98)
    at com.google.cloud.storage.spi.DefaultStorageRpc.read(DefaultStorageRpc.java:474)
    at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:127)
    at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:124)
    at com.google.cloud.RetryHelper.doRetry(RetryHelper.java:181)
    at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:247)
    at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:237)
    at com.google.cloud.storage.BlobReadChannel.read(BlobReadChannel.java:124)
    at com.google.common.io.ByteStreams.copy(ByteStreams.java:148)
    at ...
Caused by: java.io.EOFException
    at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:264)
    at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:255)
    at java.util.zip.GZIPInputStream.readUInt(GZIPInputStream.java:247)
    at java.util.zip.GZIPInputStream.readTrailer(GZIPInputStream.java:218)
    at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:118)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)
    at com.google.api.client.util.ByteStreams.copy(ByteStreams.java:51)
    at com.google.api.client.util.IOUtils.copy(IOUtils.java:94)
    at com.google.api.client.util.IOUtils.copy(IOUtils.java:63)
    at com.google.api.client.http.HttpResponse.download(HttpResponse.java:421)
    at com.google.cloud.storage.spi.DefaultStorageRpc.read(DefaultStorageRpc.java:470)
    ... 31 more

It is of course not practical to increase the chunk size indefinitely, as the whole chunk is uncompressed in memory and might create OutOfMemoryErrors.

BTW, the generated Java API client fails with the same error (I suppose it uses the same http stack for downloads).

Activity

  1. mziccard commented on May 5, 2016

    @mziccard
    mziccard
    on May 5, 2016
    Contributor
    More actions

    Hi @clementdenis thanks for your report.

    Yes the problem here is that we are reading a GZIPInputStream that contains only part (a chunk) of the compress object. When we try to read uncompressed bytes from this "partial" stream we get the error. Unfortunately this issue can not be easily overcome while still reading the uncompressed object in chunks (i.e. using ReadChannel).

    It is of course not practical to increase the chunk size indefinitely, as the whole chunk is uncompressed in memory and might create OutOfMemoryErrors.

    I agree. I will think about a solution to this and keep you posted. A possible solution would be reading each chunk without using a GZIPInputStream (and thus not trying to uncompress bytes). However, with such a solution reader.read() would still return the compressed chunk.

  2. mziccard
    added
    api: storageIssues related to the Cloud Storage API.
    on May 5, 2016
  3. mziccard commented on Sep 30, 2016

    @mziccard
    mziccard
    on Sep 30, 2016
    Contributor
    More actions

    @clementdenis while we wait for googleapis/google-api-java-client#1009 to get fixed I drafter a workaround in #1301 that allows to read a file in compressed chunks.

    Feel free to give it a try and let us know.

  4. mziccard
    closed this as completedin #1301on Oct 2, 2016
  5. JustinBeckwith
    assigned
    mziccard
    on Feb 1, 2021
  6. github-actions
    added a commit that references this issue on Jul 1, 2022

    ci: removing clirr from required checks (#982)

    78f7537
  7. github-actions
    added a commit that references this issue on Aug 16, 2022

    chore(deps): update dependency com.google.cloud:google-cloud-dialogfl…

    7f73975
  8. github-actions
    added 3 commits that reference this issue on Sep 15, 2022

    chore: Generated snippets should not be owned by samples reviewers (#…

    cef8606

    deps: update dependency com.google.cloud:google-cloud-pubsub to v1.12…

    8ac525a

    chore(main): release 3.7.0 (#978)

    085a8f7
  9. suztomo
    added a commit that references this issue on Feb 1, 2023

    chore(main): release 2.8.22 (#982)

    c482e62
  10. meltsufin
    added a commit that references this issue on Dec 22, 2025

    chore: update dependencies for regapic (#1467) (#982)

    5eaa500
  11. chingor13
    added a commit that references this issue on Jan 6, 2026

    chore(main): release 0.129.1-SNAPSHOT (#982)

    247dc4e
  12. chingor13
    added a commit that references this issue on Feb 24, 2026

    feat: adds configurable token lifetime support (#982)

    0198733
  13. suztomo
    added a commit that references this issue on Mar 11, 2026

    chore: update dependencies for regapic (googleapis#1467) (googleapis#982

    d3ec0e9
  14. chingor13
    added a commit that references this issue on Mar 12, 2026

    feat: adds configurable token lifetime support (#982)

    3be826d
  15. suztomo
    added a commit that references this issue on Mar 30, 2026

    chore(main): release 0.124.15 (#982)

    353f20b
  16. lqiu96
    added a commit that references this issue on Apr 1, 2026

    chore(main): release 0.124.15 (#982)

    0a545f8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @mziccard
    mziccard

Labels

api: storageIssues related to the Cloud Storage API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.