Object Storage Service (OSS) can automatically decompress ZIP files. To decompress files in other formats, such as .tar.gz, .tar.bz2, and .tar.xz, you can create an OSS event trigger in Function Compute and code the logic of the trigger to decompress such files. This topic describes how to automatically decompress files uploaded to OSS in different formats.

Prerequisites

Before you begin, make sure that you have completed the following operations:

Background information

The following flowchart shows the decompression process.principle
Note We recommend that you use the standard ZIP and TAR commands to compress files and that your functions use Python 3.6 libraries for decompression.

Decompress a large file

If a compressed file is large and contains many files, decompression may time out and fail to complete. Function Compute can work together with Serverless Workflow to decompress large numbers of files.

  1. Log on to the Function Compute console.
  2. In the left-side navigation pane, click Application Center.
  3. On the Application Center page, click Create Application Based on a Template.
    image1
  4. In the Create Application wizard, select Unzip Oss File and click Configure and Deploy in the Select Template step.
    image2
  5. On the Unzip Oss File page, set the parameters and click Deploy.
    Note This application is available only in the China (Hangzhou), China (Shanghai), China (Beijing), and China (Shenzhen) regions. Only ZIP files can be decompressed.

    If this solution cannot meet your needs, contact us.

Configure decompression for different file formats

  1. You can perform the following operations to decompress the sample project:
    • If you have installed Git, run the following command:
      git clone https://github.com/awesome-fc/decompress-oss.git
    • If you have not installed Git, download the code package.
  2. Modify and save the template.yml file.
    1. Change the value of the BucketName parameter to the name of your bucket.
    2. Change the value of the Project parameter from decompress-log-pro to the name of your project. Project names must be globally unique.
    3. When you configure the OSS event trigger, change the values of the Prefix, Suffix, and PROCESSED_DIR parameters as needed. PROCESSED_DIR specifies the directory where you want to save decompressed files.
      Note OSS event triggers use the src/ prefix and the dst/ directory by default.
  3. In the directory that contains the template.yml file, run the fun deploy command to deploy your project.
  4. After your project is deployed, you can upload compressed files with a .zip, .tar.gz, .tar.bz2, or .tar.xz extension to the specified directory in your bucket. When the upload is successful, the function is triggered to decompress the files. The default directory for storing compressed files is src/.
    The function automatically decompresses the files to the target directory. The default directory for storing decompressed files is dst.