Skip to content

Commit 697e9d9

Browse files
committed
Clean up, add s3Prefix to downloader
1 parent 0e6213b commit 697e9d9

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

swift/example_code/s3-transfer-manager/download-streaming/Package.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@
22
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
// SPDX-License-Identifier: Apache-2.0
44
//
5-
// (swift-tools-version has two lines here because it needs to be the first
6-
// line in the file, but it should also appear in the snippet below)
7-
//
8-
// snippet-start:[swift.rds.scenario.package]
9-
// swift-tools-version: 5.9
10-
//
115
// The swift-tools-version declares the minimum version of Swift required to
126
// build this package.
137

148
import PackageDescription
159

1610
let package = Package(
17-
name: "getbucket",
11+
name: "downloadbucket",
1812
// Let Xcode know the minimum Apple platforms supported.
1913
platforms: [
2014
.macOS(.v13),
@@ -38,7 +32,7 @@ let package = Package(
3832
// Targets can depend on other targets in this package and products
3933
// from dependencies.
4034
.executableTarget(
41-
name: "getbucket",
35+
name: "downloadbucket",
4236
dependencies: [
4337
.product(name: "AWSS3", package: "aws-sdk-swift"),
4438
.product(name: "S3TransferManager", package: "aws-sdk-swift-s3-transfer-manager"),
@@ -48,4 +42,3 @@ let package = Package(
4842

4943
]
5044
)
51-
// snippet-end:[swift.rds.scenario.package]

swift/example_code/s3-transfer-manager/download-streaming/Sources/Example.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import Foundation
1313
class Example {
1414
let region: String
1515
let bucketName: String
16+
let s3Prefix: String?
1617

17-
init(region: String, bucket: String) {
18+
init(region: String, bucket: String, s3Prefix: String?) {
1819
self.region = region
1920
self.bucketName = bucket
21+
self.s3Prefix = s3Prefix
2022
}
2123

2224
/// The body of the example.
@@ -81,6 +83,7 @@ class Example {
8183
input: DownloadBucketInput(
8284
bucket: bucketName,
8385
destination: targetDirectory,
86+
s3Prefix: s3Prefix,
8487
// The listener for the overall bucket download process.
8588
directoryTransferListeners: [downloadBucketStreamingTransferListener],
8689
// A factory that creates a listener for each file being downloaded.
@@ -92,15 +95,15 @@ class Example {
9295
switch downloadObjectTransferEvent {
9396
// The download of a file has begun.
9497
case .initiated(let input, _):
95-
print(" Downloading file \(input.key)...")
98+
print("Downloading file \(input.key)...")
9699

97100
// The number of bytes received so far has been updated.
98101
case .bytesTransferred(let input, let snapshot):
99102
print(" Transferred \(snapshot.transferredBytes) total bytes of file \(input.key)...")
100103

101104
// A file download has completed.
102105
case .complete(let input, _, let snapshot):
103-
print(" Finished downloading file \(input.key) (\(snapshot.transferredBytes) bytes).")
106+
print("Finished downloading file \(input.key) (\(snapshot.transferredBytes) bytes).")
104107
objectListener.closeStream()
105108

106109
// The download of the file has failed.

swift/example_code/s3-transfer-manager/download-streaming/Sources/entry.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ struct ExampleCommand: ParsableCommand {
99
var region = "us-east-1"
1010
@Argument(help: "Name of the Amazon S3 bucket to download")
1111
var bucketName: String
12+
@Argument(help: "Prefix to download (allows downloading a subset of the bucket)")
13+
var s3Prefix: String?
1214

1315
static var configuration = CommandConfiguration(
14-
commandName: "getbucket",
16+
commandName: "downloadbucket",
1517
abstract: """
16-
Downloads a bucket from Amazon S3 using the S3 Transfer Manager.
18+
Downloads a bucket from Amazon S3 using the S3 Transfer Manager, with progress updates.
1719
""",
1820
discussion: """
1921
"""
@@ -22,7 +24,7 @@ struct ExampleCommand: ParsableCommand {
2224
/// Called by ``main()`` to do the actual running of the AWS
2325
/// example.
2426
func runAsync() async throws {
25-
let example = Example(region: region, bucket: bucketName)
27+
let example = Example(region: region, bucket: bucketName, s3Prefix: s3Prefix)
2628

2729
try await example.run()
2830
}

swift/example_code/s3-transfer-manager/upload-file/Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// (swift-tools-version has two lines here because it needs to be the first
66
// line in the file, but it should also appear in the snippet below)
77
//
8-
// snippet-start:[swift.rds.scenario.package]
8+
// snippet-start:[swift.s3tm.scenario.package]
99
// swift-tools-version: 5.9
1010
//
1111
// The swift-tools-version declares the minimum version of Swift required to
@@ -48,4 +48,4 @@ let package = Package(
4848

4949
]
5050
)
51-
// snippet-end:[swift.rds.scenario.package]
51+
// snippet-end:[swift.s3tm.scenario.package]

0 commit comments

Comments
 (0)