Expand description
Streaming ZIP upload and extraction for Amazon S3.
s3-unspool zips local directories and existing S3 prefixes into local or
S3 ZIP files, and unzips local or S3 ZIP files into local directories or S3
prefixes.
Local directory and S3-prefix zip operations generate the ZIP once. S3 ZIP destinations are streamed with multipart upload, and local ZIP destinations are written through a temporary sibling file before being renamed into place. Empty local directories and zero-byte S3 marker objects are preserved as ZIP directory entries.
Extraction compares ZIP entries with destination objects listed by
ListObjectsV2. Missing objects are uploaded with If-None-Match: *, and
changed objects are uploaded with If-Match against the listed destination
ETag so newer destination data is not overwritten accidentally.
Conditional write conflicts are recorded and skipped by default; set
SyncOptions::fail_on_conflict or LocalZipSyncOptions::fail_on_conflict
to return an error on the first observed conflict.
Conditional overwrites require s3:GetObject permission on destination
objects as well as s3:PutObject. s3-unspool does not issue per-file
destination HeadObject requests or read destination object bodies, but S3
authorizes If-Match writes against object-read permission.
Destination PutObject bodies are fed by a source-range scheduler, so a body
can pause while waiting for planned ZIP bytes. For high-concurrency extracts,
consider relaxing or disabling AWS SDK upload stalled-stream protection on
the destination client. Keep download stalled-stream protection enabled for
source reads. The repository CLI and Lambda example configure this split.
Library users can call sync_zip_to_s3_with_clients when source reads and
destination writes need separate S3 client configuration.
inspect_s3_zip reads source ZIP size and file count without downloading
the archive. It is useful before choosing memory-sensitive scheduler options
with AdaptiveSourceWindow or
SyncOptions::with_source_window_memory_budget_mb.
ZIPs created with upload_directory_zip_to_s3, zip_directory_to_file,
zip_s3_prefix_to_s3, or zip_s3_prefix_to_file include an embedded catalog at
EMBEDDED_CATALOG_PATH by default. The catalog stores each file path and
MD5 digest so later extracts can skip unchanged files before decompressing
them. Set SyncOptions::force_hash_comparison when you need to measure
or force the fallback extract-and-hash path.
Set SyncOptions::with_selection or the equivalent local unzip option
when only a subset of ZIP paths should be restored. Selection patterns use
gitignore-style syntax and are applied before source range planning, so
ranged GetObject requests are planned only for selected entries that still
need source bytes. Exclude-only selections restore every non-excluded ZIP
path. Selected extracts reject SyncOptions::delete_extra_objects because
unselected destination objects are outside the restore scope.
ZIP directory entries round-trip as zero-byte S3 marker objects whose keys
end in /. Local upload preserves empty directories as ZIP directory
entries, and S3-prefix upload preserves zero-byte S3 marker objects as ZIP
directory entries while rejecting nonzero trailing-slash S3 objects as
ambiguous.
§Extract an S3 ZIP to a Destination Prefix
use aws_config::BehaviorVersion;
use aws_sdk_s3::Client;
use s3_unspool::{S3Object, S3Prefix, SyncOptions, sync_zip_to_s3};
let config = aws_config::load_defaults(BehaviorVersion::latest()).await;
let client = Client::new(&config);
let extract = SyncOptions::new(
S3Object::parse("s3://my-bucket/releases/site.zip")?,
S3Prefix::parse("s3://my-bucket/www/")?,
)
.delete_extra_objects();
let report = sync_zip_to_s3(&client, extract).await?;
println!("uploaded changed files: {}", report.summary.uploaded_changed);§Extract Selected Entries from an S3 ZIP
use aws_config::BehaviorVersion;
use aws_sdk_s3::Client;
use s3_unspool::{S3Object, S3Prefix, SyncOptions, UnzipSelection, sync_zip_to_s3};
let config = aws_config::load_defaults(BehaviorVersion::latest()).await;
let client = Client::new(&config);
let extract = SyncOptions::new(
S3Object::parse("s3://my-bucket/releases/site.zip")?,
S3Prefix::parse("s3://my-bucket/www/")?,
)
.with_selection(
UnzipSelection::new()
.include("index.md")
.include("docs/**/*.md")
.exclude("docs/drafts/**"),
);
let report = sync_zip_to_s3(&client, extract).await?;
println!("processed entries: {}", report.summary.zip_files);§Upload a Directory as a Cataloged ZIP
use aws_config::BehaviorVersion;
use aws_sdk_s3::Client;
use s3_unspool::{S3Object, UploadOptions, upload_directory_zip_to_s3};
let config = aws_config::load_defaults(BehaviorVersion::latest()).await;
let client = Client::new(&config);
let upload = UploadOptions::new(
"./site",
S3Object::parse("s3://my-bucket/releases/site.zip")?,
);
let report = upload_directory_zip_to_s3(&client, upload).await?;
println!("uploaded files: {}", report.files);§Upload an S3 Prefix as a Cataloged ZIP
use aws_config::BehaviorVersion;
use aws_sdk_s3::Client;
use s3_unspool::{S3Object, S3Prefix, S3PrefixUploadOptions, zip_s3_prefix_to_s3};
let config = aws_config::load_defaults(BehaviorVersion::latest()).await;
let client = Client::new(&config);
let upload = S3PrefixUploadOptions::new(
S3Prefix::parse("s3://my-bucket/www/")?,
S3Object::parse("s3://my-bucket/releases/site.zip")?,
);
let report = zip_s3_prefix_to_s3(&client, upload).await?;
println!("uploaded files: {}", report.files);§Assumptions
The crate assumes destination objects use single-part S3 ETags that match the MD5 digest of the object body. Multipart destination objects and SSE-C destination ETags are intentionally out of scope for comparison.
Structs§
- Adaptive
Source Window - Inputs for deriving an adaptive source block window capacity.
- DryRun
Diagnostics - Effective dry-run source settings and aggregate diagnostics.
- DryRun
Object Report - Per-object dry-run operation result.
- Local
Unzip Diagnostics - Effective local unzip settings and aggregate source diagnostics.
- Local
Unzip Options - Options for extracting a local ZIP file into a local directory.
- Local
Unzip Report - Full report returned when extracting a ZIP into a local directory.
- Local
ZipOptions - Options for zipping a local directory to a local ZIP file.
- Local
ZipReport - Summary returned by local ZIP creation helpers.
- Local
ZipSync Options - Options for extracting a local ZIP file into an S3 prefix.
- Local
ZipTo S3Report - Full report returned when extracting a local ZIP into an S3 prefix.
- Object
Report - Per-object operation result.
- PutDiagnostics
- Destination
PutObjectfailure counters. - PutRetry
Diagnostics - Effective destination
PutObjectretry settings. - PutRetry
Policy - Retry and backoff policy for destination
PutObjectattempts. - S3Object
- Parsed S3 object URI.
- S3Prefix
- Parsed S3 destination prefix URI.
- S3Prefix
Local ZipOptions - Options for zipping an S3 prefix to a local ZIP file.
- S3Prefix
Upload Options - Options for zipping an S3 prefix and uploading it as an S3 ZIP object.
- S3Prefix
Upload Report - Summary returned by
crate::zip_s3_prefix_to_s3. - S3Zip
Info - Metadata about a source ZIP object stored in S3.
- S3Zip
Local Unzip Options - Options for extracting an S3 ZIP object into a local directory.
- Source
Diagnostics - Source scheduler and ranged
GetObjectcounters. - Sync
Diagnostics - Effective extract settings and aggregate diagnostics.
- Sync
Options - Options for extracting a ZIP object from S3 into an S3 prefix.
- Sync
Report - Full report returned by
crate::sync_zip_to_s3. - Sync
Summary - Aggregate counters for an extract run.
- Unzip
DryRun Report - Full report returned by extract dry-run helpers.
- Unzip
DryRun Summary - Aggregate counters for an extract dry run.
- Unzip
Selection - ZIP entry selection patterns for unzip APIs.
- Upload
Options - Options for zipping a local directory and uploading it as an S3 object.
- Upload
Progress Handler - Upload progress callback wrapper.
- Upload
Report - Summary returned by
crate::upload_directory_zip_to_s3. - ZipDry
RunReport - Summary returned by ZIP dry-run helpers.
Enums§
- Comparison
Mode - How unzip operations compare ZIP entries with existing destination objects.
- Conflict
Policy - How unzip-to-S3 operations handle destination conditional write conflicts.
- Destination
Cleanup - How an unzip-to-S3 operation treats destination objects that are not in the ZIP.
- DryRun
Operation Status - Status for a single dry-run destination operation.
- Error
- Error type returned by
s3-unspooloperations. - Operation
Status - Status for a single destination object operation.
- Retry
Jitter - Jitter mode used for application-level destination
PutObjectretries. - Upload
Progress - Progress event emitted while preparing and streaming an upload ZIP.
- ZipCompression
- Compression method used for regular file entries when creating ZIP archives.
Constants§
- EMBEDDED_
CATALOG_ PATH - Reserved ZIP entry path used for the optional embedded update catalog.
Functions§
- adaptive_
source_ get_ concurrency - Computes adaptive source
GetObjectconcurrency for a fixed memory envelope. - dry_
run_ sync_ zip_ to_ s3 - Plans extracting an S3 ZIP object into an S3 prefix without writing or deleting objects.
- dry_
run_ sync_ zip_ to_ s3_ with_ clients - Plans extracting an S3 ZIP object into an S3 prefix with separate source and destination clients.
- dry_
run_ unzip_ file_ to_ local - Plans extracting a local ZIP file into a local directory without writing files.
- dry_
run_ unzip_ file_ to_ s3 - Plans extracting a local ZIP file into an S3 prefix without writing or deleting objects.
- dry_
run_ unzip_ s3_ zip_ to_ local - Plans extracting an S3 ZIP object into a local directory without writing files.
- dry_
run_ upload_ directory_ zip_ to_ s3 - Plans zipping a local directory and uploading it as an S3 object without writing anything.
- dry_
run_ zip_ directory_ to_ file - Plans zipping a local directory into a local ZIP file without writing anything.
- dry_
run_ zip_ s3_ prefix_ to_ file - Plans zipping an S3 prefix into a local ZIP file without writing anything.
- dry_
run_ zip_ s3_ prefix_ to_ s3 - Plans zipping an S3 prefix and uploading it as an S3 object without writing anything.
- inspect_
s3_ zip - Inspects an S3 ZIP object without downloading it to local storage.
- sync_
zip_ to_ s3 - Extracts missing or changed files from an S3 ZIP object into an S3 prefix.
- sync_
zip_ to_ s3_ with_ clients - Extracts missing or changed files from an S3 ZIP object into an S3 prefix, using separate S3 clients for source reads and destination writes.
- unzip_
file_ to_ local - Extracts a local ZIP file into a local directory.
- unzip_
file_ to_ s3 - Extracts a local ZIP file into an S3 prefix.
- unzip_
s3_ zip_ to_ local - Extracts an S3 ZIP object into a local directory.
- upload_
directory_ zip_ to_ s3 - Zips a local directory and uploads the archive to S3.
- zip_
directory_ to_ file - Zips a local directory into a local ZIP file.
- zip_
s3_ prefix_ to_ file - Zips an S3 prefix into a local ZIP file.
- zip_
s3_ prefix_ to_ s3 - Zips an S3 prefix and uploads the archive to S3.
Type Aliases§
- Result
- Result type returned by
s3-unspooloperations.