alexmojaki / s3-stream-upload

Manages streaming of data to AWS S3 without knowing the size beforehand and without keeping it all in memory or writing to disk.
MIT License
208 stars 62 forks source link

auto-flush added (optional) #1

Closed idozorenko closed 5 years ago

idozorenko commented 8 years ago

Adds optional auto-flush possibility, so as checkSize() does not have to be called manually.

adrian-herscu commented 6 years ago

Why someone would want not to flush "automatically"? I solved this by wrapping the stream provided by getMultiPartOutputStreams with a FilterOutputStream like this:

final class CheckedMultipartOutputStream
            extends FilterOutputStream {
            CheckedMultipartOutputStream(final OutputStream out) {
                super(out);
            }

            @Override
            @SneakyThrows
            public void write(final byte[] b)
                throws IOException {
                super.write(b);
                out().checkSize();
            }
....
alexmojaki commented 5 years ago

Thanks guys, and sorry I never responded to this. There was a time when I thought that checkSize being called too eagerly could lead to malformed data, that was a mistake. I have released a version 2.0 in which the method is no longer public and is called automatically.