unzip — Extract files from ZIP archives in MATLAB and RunMat.
unzip(zipfilename) extracts a ZIP archive into the current folder. unzip(zipfilename, outputfolder) extracts into the requested destination folder. The first argument can be a local file path or an HTTP/HTTPS URL, and filenames = unzip(...) returns a cell array of extracted file paths.
Syntax
unzip(zipfilename)
unzip(zipfilename, outputfolder)
filenames = unzip(___)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
zipfilename | StringScalar | Yes | — | ZIP archive path or HTTP/HTTPS URL. |
outputfolder | StringScalar | Yes | — | Destination folder for extracted files. |
Returns
| Name | Type | Description |
|---|---|---|
filenames | Any | Cell array of extracted file paths. |
Returned values from unzip depend on how many outputs the caller requests.
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:unzip:InvalidArgument | Arguments do not match supported unzip invocation forms. | unzip: invalid argument |
RunMat:unzip:Filename | ZIP filename or URL is invalid. | unzip: invalid ZIP filename |
RunMat:unzip:OutputFolder | Output folder is invalid or cannot be created. | unzip: invalid output folder |
RunMat:unzip:Http | Remote ZIP archive cannot be downloaded. | unzip: download failed |
RunMat:unzip:Zip | ZIP archive cannot be decoded or contains unsupported entries. | unzip: invalid ZIP archive |
RunMat:unzip:UnsafePath | ZIP entry would escape the destination folder. | unzip: unsafe archive path |
RunMat:unzip:Io | Extraction fails due to filesystem I/O. | unzip: extraction failed |
RunMat:unzip:Output | Returned filename cell array cannot be materialized. | unzip: output materialization failed |
RunMat:unzip:OutputCount | Caller requests more outputs than unzip supports. | unzip: unsupported output count |
How unzip works
unzip(zipfilename)extracts all non-directory entries into the current working folder.unzip(zipfilename, outputfolder)createsoutputfolderwhen needed and extracts all entries beneath that folder.unzip(url, outputfolder)downloads the archive over HTTP or HTTPS using RunMat's shared HTTP transport, then extracts it.- Returned filenames are a column cell array of character paths for regular files that were extracted. Directory entries are created as needed but are not included in the returned list.
- Archive entries with absolute paths, user-relative paths, drive-prefixed names, or
..parent traversal are rejected before writing, preventing zip-slip extraction outside the destination folder. - Remote ZIP downloads are capped before extraction, and extracted bytes are counted while streaming each entry so malformed archives cannot grow without bound.
- ZIP entries compressed with the standard deflate method are supported. Unsupported or malformed ZIP archives raise a
RunMat:unzip:Zipdiagnostic. unzipis a host I/O sink. It suppresses statement-form auto output, and when called with zero requested outputs it still extracts files but returns no value.
Does RunMat run unzip on the GPU?
unzip is registered as a host I/O operation. Fusion groups terminate before archive extraction and no Accelerate provider hooks are used.
GPU memory and residency
No manual action is required. Path arguments are gathered to host values and extraction writes host filesystem files.
Examples
Extract into the current folder
unzip('sampleData.zip')Extract into a specific output folder
files = unzip('sampleData.zip', 'data')Download and extract a ZIP archive
files = unzip('https://example.com/sampleData.zip', tempdir)Use the returned file list
files = unzip('measurements.zip', 'measurements');
firstFile = files{1};Using unzip with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how unzip changes the result.
Run a small unzip example, explain the result, then change one input and compare the output.
FAQ
Does unzip create the destination folder?⌄
Yes. The output folder and any archive subfolders are created when needed.
Can unzip extract archives from URLs?⌄
Yes. HTTP and HTTPS URLs are downloaded with RunMat's shared HTTP transport before extraction.
Are directory entries returned in filenames?⌄
No. Directory entries are created, but the returned cell array contains regular extracted file paths.
How are unsafe ZIP paths handled?⌄
RunMat rejects entries that would escape the destination folder, including absolute paths, .. traversal, drive-prefixed names, and user-relative paths.
Does unzip run on the GPU?⌄
No. Archive extraction is filesystem and network I/O, so it always runs on the host.
Related Io functions
Repl Fs
addpath · cd · copyfile · delete · dir · exist · fullfile · genpath · getenv · ls · mkdir · movefile · path · pwd · rmdir · rmpath · run · savepath · setenv · tempdir · tempname · uigetfile · uiputfile
Tabular
csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · readmatrix · spreadsheetImportOptions · writecell · writematrix · xlsread
Filetext
fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite
Import
Json
Http
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how unzip is executed, line by line, in Rust.
- View the source for unzip in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.