UNPKG

7.65 kBTypeScriptView Raw
1/*!
2 * Copyright 2022 Google LLC. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { Bucket, UploadOptions, UploadResponse } from './bucket';
17import { DownloadOptions, DownloadResponse, File } from './file';
18export interface UploadManyFilesOptions {
19 concurrencyLimit?: number;
20 skipIfExists?: boolean;
21 prefix?: string;
22 passthroughOptions?: Omit<UploadOptions, 'destination'>;
23}
24export interface DownloadManyFilesOptions {
25 concurrencyLimit?: number;
26 prefix?: string;
27 stripPrefix?: string;
28 passthroughOptions?: DownloadOptions;
29}
30export interface DownloadFileInChunksOptions {
31 concurrencyLimit?: number;
32 chunkSizeBytes?: number;
33 destination?: string;
34 validation?: 'crc32c' | false;
35}
36/**
37 * Create a TransferManager object to perform parallel transfer operations on a Cloud Storage bucket.
38 *
39 * @class
40 * @hideconstructor
41 *
42 * @param {Bucket} bucket A {@link Bucket} instance
43 * @experimental
44 */
45export declare class TransferManager {
46 bucket: Bucket;
47 constructor(bucket: Bucket);
48 /**
49 * @typedef {object} UploadManyFilesOptions
50 * @property {number} [concurrencyLimit] The number of concurrently executing promises
51 * to use when uploading the files.
52 * @property {boolean} [skipIfExists] Do not upload the file if it already exists in
53 * the bucket. This will set the precondition ifGenerationMatch = 0.
54 * @property {string} [prefix] A prefix to append to all of the uploaded files.
55 * @property {object} [passthroughOptions] {@link UploadOptions} Options to be passed through
56 * to each individual upload operation.
57 * @experimental
58 */
59 /**
60 * Upload multiple files in parallel to the bucket. This is a convenience method
61 * that utilizes {@link Bucket#upload} to perform the upload.
62 *
63 * @param {array | string} [filePathsOrDirectory] An array of fully qualified paths to the files or a directory name.
64 * If a directory name is provided, the directory will be recursively walked and all files will be added to the upload list.
65 * to be uploaded to the bucket
66 * @param {UploadManyFilesOptions} [options] Configuration options.
67 * @returns {Promise<UploadResponse[]>}
68 *
69 * @example
70 * ```
71 * const {Storage} = require('@google-cloud/storage');
72 * const storage = new Storage();
73 * const bucket = storage.bucket('my-bucket');
74 * const transferManager = new TransferManager(bucket);
75 *
76 * //-
77 * // Upload multiple files in parallel.
78 * //-
79 * const response = await transferManager.uploadManyFiles(['/local/path/file1.txt, 'local/path/file2.txt']);
80 * // Your bucket now contains:
81 * // - "local/path/file1.txt" (with the contents of '/local/path/file1.txt')
82 * // - "local/path/file2.txt" (with the contents of '/local/path/file2.txt')
83 * const response = await transferManager.uploadManyFiles('/local/directory');
84 * // Your bucket will now contain all files contained in '/local/directory' maintaining the subdirectory structure.
85 * ```
86 * @experimental
87 */
88 uploadManyFiles(filePathsOrDirectory: string[] | string, options?: UploadManyFilesOptions): Promise<UploadResponse[]>;
89 /**
90 * @typedef {object} DownloadManyFilesOptions
91 * @property {number} [concurrencyLimit] The number of concurrently executing promises
92 * to use when downloading the files.
93 * @property {string} [prefix] A prefix to append to all of the downloaded files.
94 * @property {string} [stripPrefix] A prefix to remove from all of the downloaded files.
95 * @property {object} [passthroughOptions] {@link DownloadOptions} Options to be passed through
96 * to each individual download operation.
97 * @experimental
98 */
99 /**
100 * Download multiple files in parallel to the local filesystem. This is a convenience method
101 * that utilizes {@link File#download} to perform the download.
102 *
103 * @param {array | string} [filesOrFolder] An array of file name strings or file objects to be downloaded. If
104 * a string is provided this will be treated as a GCS prefix and all files with that prefix will be downloaded.
105 * @param {DownloadManyFilesOptions} [options] Configuration options.
106 * @returns {Promise<DownloadResponse[]>}
107 *
108 * @example
109 * ```
110 * const {Storage} = require('@google-cloud/storage');
111 * const storage = new Storage();
112 * const bucket = storage.bucket('my-bucket');
113 * const transferManager = new TransferManager(bucket);
114 *
115 * //-
116 * // Download multiple files in parallel.
117 * //-
118 * const response = await transferManager.downloadManyFiles(['file1.txt', 'file2.txt']);
119 * // The following files have been downloaded:
120 * // - "file1.txt" (with the contents from my-bucket.file1.txt)
121 * // - "file2.txt" (with the contents from my-bucket.file2.txt)
122 * const response = await transferManager.downloadManyFiles([bucket.File('file1.txt'), bucket.File('file2.txt')]);
123 * // The following files have been downloaded:
124 * // - "file1.txt" (with the contents from my-bucket.file1.txt)
125 * // - "file2.txt" (with the contents from my-bucket.file2.txt)
126 * const response = await transferManager.downloadManyFiles('test-folder');
127 * // All files with GCS prefix of 'test-folder' have been downloaded.
128 * ```
129 * @experimental
130 */
131 downloadManyFiles(filesOrFolder: File[] | string[] | string, options?: DownloadManyFilesOptions): Promise<void | DownloadResponse[]>;
132 /**
133 * @typedef {object} DownloadFileInChunksOptions
134 * @property {number} [concurrencyLimit] The number of concurrently executing promises
135 * to use when downloading the file.
136 * @property {number} [chunkSizeBytes] The size in bytes of each chunk to be downloaded.
137 * @property {string | boolean} [validation] Whether or not to perform a CRC32C validation check when download is complete.
138 * @experimental
139 */
140 /**
141 * Download a large file in chunks utilizing parallel download operations. This is a convenience method
142 * that utilizes {@link File#download} to perform the download.
143 *
144 * @param {object} [file | string] {@link File} to download.
145 * @param {DownloadFileInChunksOptions} [options] Configuration options.
146 * @returns {Promise<DownloadResponse>}
147 *
148 * @example
149 * ```
150 * const {Storage} = require('@google-cloud/storage');
151 * const storage = new Storage();
152 * const bucket = storage.bucket('my-bucket');
153 * const transferManager = new TransferManager(bucket);
154 *
155 * //-
156 * // Download a large file in chunks utilizing parallel operations.
157 * //-
158 * const response = await transferManager.downloadLargeFile(bucket.file('large-file.txt');
159 * // Your local directory now contains:
160 * // - "large-file.txt" (with the contents from my-bucket.large-file.txt)
161 * ```
162 * @experimental
163 */
164 downloadFileInChunks(fileOrName: File | string, options?: DownloadFileInChunksOptions): Promise<void | DownloadResponse>;
165 private getPathsFromDirectory;
166}