GithubHelp home page GithubHelp logo

beannguyengw / s3-stream-unzip Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nejckorasa/s3-stream-unzip

0.0 0.0 0.0 210 KB

Java library to manage unzipping of large files and data in AWS S3 without knowing the size beforehand and without keeping it all in memory or writing to disk.

License: MIT License

Java 100.00%

s3-stream-unzip's Introduction

Maven Build Maven Central

s3-stream-unzip

Manages unzipping of data in AWS S3 utilizing stream download and multipart upload.

Unzipping is achieved without knowing the size beforehand and without keeping it all in memory or writing to disk. That makes it suitable for large data files - it has been used to unzip files of size 100GB+.

Supports different unzip strategies including an option to split zipped files (suitable for larger files), see SplitTextUnzipStrategy.

See tests (namely S3UnzipManagerTest) for examples on how to use S3UnzipManager.java to manage unzipping, some examples:

// initialize AmazonS3 client
AmazonS3 s3CLient = AmazonS3ClientBuilder.standard()
        // customize the client
        .build()

// create UnzipStrategy
var strategy = new NoSplitUnzipStrategy();
var strategy = new SplitTextUnzipStrategy()
        .withHeader(true)
        .withFileBytesLimit(100 * MB);

// or create UnzipStrategy with additional config
var config = new S3MultipartUpload.Config()
        .withThreadCount(5)
        .withQueueSize(5)
        .withAwaitTerminationTimeSeconds(2)
        .withCannedAcl(CannedAccessControlList.BucketOwnerFullControl)
        .withUploadPartBytesLimit(20 * MB)
        .withCustomizeInitiateUploadRequest(request -> {
            // customize request
            return request;
        });

var strategy = new NoSplitUnzipStrategy(config);

// create S3UnzipManager
var um = new S3UnzipManager(s3Client, strategy);
var um = new S3UnzipManager(s3Client, strategy.withContentTypes(List.of("application/zip"));

// unzip options
um.unzipObjects("bucket-name", "input-path", "output-path");
um.unzipObjectsKeyMatching("bucket-name", "input-path", "output-path", ".*\\.zip");
um.unzipObjectsKeyContaining("bucket-name", "input-path", "output-path", "-part-of-object-");
um.unzipObject(s3Object, "output-path");

Inspired by: https://medium.com/@pra4mesh/uploading-inputstream-to-aws-s3-using-multipart-upload-java-add81b57964e

Usage

Available on Maven Central.

Maven

<dependency>
    <groupId>io.github.nejckorasa</groupId>
    <artifactId>s3-stream-unzip</artifactId>
    <version>1.0.0</version>
</dependency>

Gradle

compile 'io.github.nejckorasa:s3-stream-unzip:1.0.0'

Unzip strategies

All strategies utilise stream download and multipart upload - unzipping is achieved without keeping all data in memory or writing to disk.

Refer to tests for usage examples.

Unzips and uploads a file without splitting (sharding) - it creates a 1:1 mapping between zipped and unzipped file.

  • File is read in bytes.

This strategy should ideally be used for smaller files.

Unzips and uploads a text file with splitting (sharding) - it creates a 1:n mappings between zipped and unzipped files.

  • It reads the file as UTF-8 text file split into lines.
  • Provides configurable file (shard) size.
  • Can be configured to accommodate files with headers (e.g. csv files).

This strategy is suitable for larger files as it splits them into smaller, more manageable unzipped files (shards).

s3-stream-unzip's People

Contributors

nejckorasa avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.