unzip

The unzip statement is used to unzip the data in a named buffer.

Syntax

unzip_{buffer_name}

Details

The unzip statement will extract a single file from a zip archive stored in a named buffer. In order for this to succeed, the buffer must have been previously populated using the buffer statement, and the data within the buffer must be a valid ZIP file.

Only ZIP files are supported. To extract GZIP files, use gunzip.

A warning will be logged, the buffer left intact and the script will continue to execute if any of the following conditions arise:

  • The buffer is empty or does not contain a valid ZIP archive
  • The ZIP archive is damaged or otherwise corrupted
  • More than 1 file is present within the archive

After the unzip statement completes, the buffer will contain the unzipped data (the original ZIP archive is discarded during this process).

The filename of the unpacked file is also discarded, as the resulting data is stored in the buffer and can subsequently be saved using an explicit filename as shown in the example.


Example

buffer zippedData = FILE system/extracted/my_source/${dataDate}_usage.zip
          unzip {zippedData}
          save {zippedData} as system/extracted/my_source/${dataDate}_usage.csv
          discard {zippedData}

How did we do?