UNPKG

35 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="node" />
3/// <reference types="node" />
4/// <reference types="node" />
5import { BodyResponseCallback, DecorateRequestOptions, GetConfig, Metadata, MetadataCallback, ServiceObject, SetMetadataResponse } from './nodejs-common';
6import { Writable, Readable } from 'stream';
7import * as http from 'http';
8import { PreconditionOptions, Storage } from './storage';
9import { AvailableServiceObjectMethods, Bucket } from './bucket';
10import { Acl } from './acl';
11import { GetSignedUrlResponse, GetSignedUrlCallback, URLSigner, Query } from './signer';
12import { ResponseBody, Duplexify } from './nodejs-common/util';
13import { CRC32CValidatorGenerator } from './crc32c';
14import { URL } from 'url';
15import { DeleteCallback, DeleteOptions, SetMetadataOptions } from './nodejs-common/service-object';
16import * as r from 'teeny-request';
17export type GetExpirationDateResponse = [Date];
18export interface GetExpirationDateCallback {
19 (err: Error | null, expirationDate?: Date | null, apiResponse?: Metadata): void;
20}
21export interface PolicyDocument {
22 string: string;
23 base64: string;
24 signature: string;
25}
26export type GenerateSignedPostPolicyV2Response = [PolicyDocument];
27export interface GenerateSignedPostPolicyV2Callback {
28 (err: Error | null, policy?: PolicyDocument): void;
29}
30export interface GenerateSignedPostPolicyV2Options {
31 equals?: string[] | string[][];
32 expires: string | number | Date;
33 startsWith?: string[] | string[][];
34 acl?: string;
35 successRedirect?: string;
36 successStatus?: string;
37 contentLengthRange?: {
38 min?: number;
39 max?: number;
40 };
41}
42export interface PolicyFields {
43 [key: string]: string;
44}
45export interface GenerateSignedPostPolicyV4Options {
46 expires: string | number | Date;
47 bucketBoundHostname?: string;
48 virtualHostedStyle?: boolean;
49 conditions?: object[];
50 fields?: PolicyFields;
51}
52export interface GenerateSignedPostPolicyV4Callback {
53 (err: Error | null, output?: SignedPostPolicyV4Output): void;
54}
55export type GenerateSignedPostPolicyV4Response = [SignedPostPolicyV4Output];
56export interface SignedPostPolicyV4Output {
57 url: string;
58 fields: PolicyFields;
59}
60export interface GetSignedUrlConfig {
61 action: 'read' | 'write' | 'delete' | 'resumable';
62 version?: 'v2' | 'v4';
63 virtualHostedStyle?: boolean;
64 cname?: string;
65 contentMd5?: string;
66 contentType?: string;
67 expires: string | number | Date;
68 accessibleAt?: string | number | Date;
69 extensionHeaders?: http.OutgoingHttpHeaders;
70 promptSaveAs?: string;
71 responseDisposition?: string;
72 responseType?: string;
73 queryParams?: Query;
74}
75export interface GetFileMetadataOptions {
76 userProject?: string;
77}
78export type GetFileMetadataResponse = [Metadata, Metadata];
79export interface GetFileMetadataCallback {
80 (err: Error | null, metadata?: Metadata, apiResponse?: Metadata): void;
81}
82export interface GetFileOptions extends GetConfig {
83 userProject?: string;
84}
85export type GetFileResponse = [File, Metadata];
86export interface GetFileCallback {
87 (err: Error | null, file?: File, apiResponse?: Metadata): void;
88}
89export interface FileExistsOptions {
90 userProject?: string;
91}
92export type FileExistsResponse = [boolean];
93export interface FileExistsCallback {
94 (err: Error | null, exists?: boolean): void;
95}
96export interface DeleteFileOptions {
97 ignoreNotFound?: boolean;
98 userProject?: string;
99}
100export type DeleteFileResponse = [Metadata];
101export interface DeleteFileCallback {
102 (err: Error | null, apiResponse?: Metadata): void;
103}
104export type PredefinedAcl = 'authenticatedRead' | 'bucketOwnerFullControl' | 'bucketOwnerRead' | 'private' | 'projectPrivate' | 'publicRead';
105export interface CreateResumableUploadOptions {
106 chunkSize?: number;
107 highWaterMark?: number;
108 metadata?: Metadata;
109 origin?: string;
110 offset?: number;
111 predefinedAcl?: PredefinedAcl;
112 private?: boolean;
113 public?: boolean;
114 uri?: string;
115 userProject?: string;
116 preconditionOpts?: PreconditionOptions;
117}
118export type CreateResumableUploadResponse = [string];
119export interface CreateResumableUploadCallback {
120 (err: Error | null, uri?: string): void;
121}
122export interface CreateWriteStreamOptions extends CreateResumableUploadOptions {
123 contentType?: string;
124 gzip?: string | boolean;
125 resumable?: boolean;
126 timeout?: number;
127 validation?: string | boolean;
128}
129export interface MakeFilePrivateOptions {
130 metadata?: Metadata;
131 strict?: boolean;
132 userProject?: string;
133 preconditionOpts?: PreconditionOptions;
134}
135export type MakeFilePrivateResponse = [Metadata];
136export type MakeFilePrivateCallback = SetFileMetadataCallback;
137export interface IsPublicCallback {
138 (err: Error | null, resp?: boolean): void;
139}
140export type IsPublicResponse = [boolean];
141export type MakeFilePublicResponse = [Metadata];
142export interface MakeFilePublicCallback {
143 (err?: Error | null, apiResponse?: Metadata): void;
144}
145export type MoveResponse = [Metadata];
146export interface MoveCallback {
147 (err: Error | null, destinationFile?: File | null, apiResponse?: Metadata): void;
148}
149export interface MoveOptions {
150 userProject?: string;
151 preconditionOpts?: PreconditionOptions;
152}
153export type RenameOptions = MoveOptions;
154export type RenameResponse = MoveResponse;
155export type RenameCallback = MoveCallback;
156export type RotateEncryptionKeyOptions = string | Buffer | EncryptionKeyOptions;
157export interface EncryptionKeyOptions {
158 encryptionKey?: string | Buffer;
159 kmsKeyName?: string;
160 preconditionOpts?: PreconditionOptions;
161}
162export type RotateEncryptionKeyCallback = CopyCallback;
163export type RotateEncryptionKeyResponse = CopyResponse;
164export declare enum ActionToHTTPMethod {
165 read = "GET",
166 write = "PUT",
167 delete = "DELETE",
168 resumable = "POST"
169}
170/**
171 * @private
172 */
173export declare const STORAGE_POST_POLICY_BASE_URL = "https://storage.googleapis.com";
174export interface FileOptions {
175 crc32cGenerator?: CRC32CValidatorGenerator;
176 encryptionKey?: string | Buffer;
177 generation?: number | string;
178 kmsKeyName?: string;
179 preconditionOpts?: PreconditionOptions;
180 userProject?: string;
181}
182export interface CopyOptions {
183 cacheControl?: string;
184 contentEncoding?: string;
185 contentType?: string;
186 contentDisposition?: string;
187 destinationKmsKeyName?: string;
188 metadata?: Metadata;
189 predefinedAcl?: string;
190 token?: string;
191 userProject?: string;
192 preconditionOpts?: PreconditionOptions;
193}
194export type CopyResponse = [File, Metadata];
195export interface CopyCallback {
196 (err: Error | null, file?: File | null, apiResponse?: Metadata): void;
197}
198export type DownloadResponse = [Buffer];
199export type DownloadCallback = (err: RequestError | null, contents: Buffer) => void;
200export interface DownloadOptions extends CreateReadStreamOptions {
201 destination?: string;
202}
203export interface CreateReadStreamOptions {
204 userProject?: string;
205 validation?: 'md5' | 'crc32c' | false | true;
206 start?: number;
207 end?: number;
208 decompress?: boolean;
209}
210export interface SaveOptions extends CreateWriteStreamOptions {
211 onUploadProgress?: (progressEvent: any) => void;
212}
213export interface SaveCallback {
214 (err?: Error | null): void;
215}
216export interface SetFileMetadataOptions {
217 userProject?: string;
218}
219export interface SetFileMetadataCallback {
220 (err?: Error | null, apiResponse?: Metadata): void;
221}
222export type SetFileMetadataResponse = [Metadata];
223export type SetStorageClassResponse = [Metadata];
224export interface SetStorageClassOptions {
225 userProject?: string;
226 preconditionOpts?: PreconditionOptions;
227}
228export interface SetStorageClassCallback {
229 (err?: Error | null, apiResponse?: Metadata): void;
230}
231export declare class RequestError extends Error {
232 code?: string;
233 errors?: Error[];
234}
235export declare enum FileExceptionMessages {
236 EXPIRATION_TIME_NA = "An expiration time is not available.",
237 DESTINATION_NO_NAME = "Destination file should have a name.",
238 INVALID_VALIDATION_FILE_RANGE = "Cannot use validation with file ranges (start/end).",
239 MD5_NOT_AVAILABLE = "MD5 verification was specified, but is not available for the requested object. MD5 is not available for composite objects.",
240 EQUALS_CONDITION_TWO_ELEMENTS = "Equals condition must be an array of 2 elements.",
241 STARTS_WITH_TWO_ELEMENTS = "StartsWith condition must be an array of 2 elements.",
242 CONTENT_LENGTH_RANGE_MIN_MAX = "ContentLengthRange must have numeric min & max fields.",
243 DOWNLOAD_MISMATCH = "The downloaded data did not match the data from the server. To be sure the content is the same, you should download the file again.",
244 UPLOAD_MISMATCH_DELETE_FAIL = "The uploaded data did not match the data from the server.\n As a precaution, we attempted to delete the file, but it was not successful.\n To be sure the content is the same, you should try removing the file manually,\n then uploading the file again.\n \n\nThe delete attempt failed with this message:\n\n ",
245 UPLOAD_MISMATCH = "The uploaded data did not match the data from the server.\n As a precaution, the file has been deleted.\n To be sure the content is the same, you should try uploading the file again."
246}
247/**
248 * A File object is created from your {@link Bucket} object using
249 * {@link Bucket#file}.
250 *
251 * @class
252 */
253declare class File extends ServiceObject<File> {
254 #private;
255 acl: Acl;
256 crc32cGenerator: CRC32CValidatorGenerator;
257 bucket: Bucket;
258 storage: Storage;
259 kmsKeyName?: string;
260 userProject?: string;
261 signer?: URLSigner;
262 metadata: Metadata;
263 name: string;
264 generation?: number;
265 parent: Bucket;
266 private encryptionKey?;
267 private encryptionKeyBase64?;
268 private encryptionKeyHash?;
269 private encryptionKeyInterceptor?;
270 private instanceRetryValue?;
271 instancePreconditionOpts?: PreconditionOptions;
272 /**
273 * Cloud Storage uses access control lists (ACLs) to manage object and
274 * bucket access. ACLs are the mechanism you use to share objects with other
275 * users and allow other users to access your buckets and objects.
276 *
277 * An ACL consists of one or more entries, where each entry grants permissions
278 * to an entity. Permissions define the actions that can be performed against
279 * an object or bucket (for example, `READ` or `WRITE`); the entity defines
280 * who the permission applies to (for example, a specific user or group of
281 * users).
282 *
283 * The `acl` object on a File instance provides methods to get you a list of
284 * the ACLs defined on your bucket, as well as set, update, and delete them.
285 *
286 * See {@link http://goo.gl/6qBBPO| About Access Control lists}
287 *
288 * @name File#acl
289 * @mixes Acl
290 *
291 * @example
292 * ```
293 * const {Storage} = require('@google-cloud/storage');
294 * const storage = new Storage();
295 * const myBucket = storage.bucket('my-bucket');
296 *
297 * const file = myBucket.file('my-file');
298 * //-
299 * // Make a file publicly readable.
300 * //-
301 * const options = {
302 * entity: 'allUsers',
303 * role: storage.acl.READER_ROLE
304 * };
305 *
306 * file.acl.add(options, function(err, aclObject) {});
307 *
308 * //-
309 * // If the callback is omitted, we'll return a Promise.
310 * //-
311 * file.acl.add(options).then(function(data) {
312 * const aclObject = data[0];
313 * const apiResponse = data[1];
314 * });
315 * ```
316 */
317 /**
318 * The API-formatted resource description of the file.
319 *
320 * Note: This is not guaranteed to be up-to-date when accessed. To get the
321 * latest record, call the `getMetadata()` method.
322 *
323 * @name File#metadata
324 * @type {object}
325 */
326 /**
327 * The file's name.
328 * @name File#name
329 * @type {string}
330 */
331 /**
332 * @callback Crc32cGeneratorToStringCallback
333 * A method returning the CRC32C as a base64-encoded string.
334 *
335 * @returns {string}
336 *
337 * @example
338 * Hashing the string 'data' should return 'rth90Q=='
339 *
340 * ```js
341 * const buffer = Buffer.from('data');
342 * crc32c.update(buffer);
343 * crc32c.toString(); // 'rth90Q=='
344 * ```
345 **/
346 /**
347 * @callback Crc32cGeneratorValidateCallback
348 * A method validating a base64-encoded CRC32C string.
349 *
350 * @param {string} [value] base64-encoded CRC32C string to validate
351 * @returns {boolean}
352 *
353 * @example
354 * Should return `true` if the value matches, `false` otherwise
355 *
356 * ```js
357 * const buffer = Buffer.from('data');
358 * crc32c.update(buffer);
359 * crc32c.validate('DkjKuA=='); // false
360 * crc32c.validate('rth90Q=='); // true
361 * ```
362 **/
363 /**
364 * @callback Crc32cGeneratorUpdateCallback
365 * A method for passing `Buffer`s for CRC32C generation.
366 *
367 * @param {Buffer} [data] data to update CRC32C value with
368 * @returns {undefined}
369 *
370 * @example
371 * Hashing buffers from 'some ' and 'text\n'
372 *
373 * ```js
374 * const buffer1 = Buffer.from('some ');
375 * crc32c.update(buffer1);
376 *
377 * const buffer2 = Buffer.from('text\n');
378 * crc32c.update(buffer2);
379 *
380 * crc32c.toString(); // 'DkjKuA=='
381 * ```
382 **/
383 /**
384 * @typedef {object} CRC32CValidator
385 * @property {Crc32cGeneratorToStringCallback}
386 * @property {Crc32cGeneratorValidateCallback}
387 * @property {Crc32cGeneratorUpdateCallback}
388 */
389 /**
390 * @callback Crc32cGeneratorCallback
391 * @returns {CRC32CValidator}
392 */
393 /**
394 * @typedef {object} FileOptions Options passed to the File constructor.
395 * @property {string} [encryptionKey] A custom encryption key.
396 * @property {number} [generation] Generation to scope the file to.
397 * @property {string} [kmsKeyName] Cloud KMS Key used to encrypt this
398 * object, if the object is encrypted by such a key. Limited availability;
399 * usable only by enabled projects.
400 * @property {string} [userProject] The ID of the project which will be
401 * billed for all requests made from File object.
402 * @property {Crc32cGeneratorCallback} [callback] A function that generates a CRC32C Validator. Defaults to {@link CRC32C}
403 */
404 /**
405 * Constructs a file object.
406 *
407 * @param {Bucket} bucket The Bucket instance this file is
408 * attached to.
409 * @param {string} name The name of the remote file.
410 * @param {FileOptions} [options] Configuration options.
411 * @example
412 * ```
413 * const {Storage} = require('@google-cloud/storage');
414 * const storage = new Storage();
415 * const myBucket = storage.bucket('my-bucket');
416 *
417 * const file = myBucket.file('my-file');
418 * ```
419 */
420 constructor(bucket: Bucket, name: string, options?: FileOptions);
421 /**
422 * The object's Cloud Storage URI (`gs://`)
423 *
424 * @example
425 * ```ts
426 * const {Storage} = require('@google-cloud/storage');
427 * const storage = new Storage();
428 * const bucket = storage.bucket('my-bucket');
429 * const file = bucket.file('image.png');
430 *
431 * // `gs://my-bucket/image.png`
432 * const href = file.cloudStorageURI.href;
433 * ```
434 */
435 get cloudStorageURI(): URL;
436 /**
437 * A helper method for determining if a request should be retried based on preconditions.
438 * This should only be used for methods where the idempotency is determined by
439 * `ifGenerationMatch`
440 * @private
441 *
442 * A request should not be retried under the following conditions:
443 * - if precondition option `ifGenerationMatch` is not set OR
444 * - if `idempotencyStrategy` is set to `RetryNever`
445 */
446 private shouldRetryBasedOnPreconditionAndIdempotencyStrat;
447 copy(destination: string | Bucket | File, options?: CopyOptions): Promise<CopyResponse>;
448 copy(destination: string | Bucket | File, callback: CopyCallback): void;
449 copy(destination: string | Bucket | File, options: CopyOptions, callback: CopyCallback): void;
450 /**
451 * @typedef {object} CreateReadStreamOptions Configuration options for File#createReadStream.
452 * @property {string} [userProject] The ID of the project which will be
453 * billed for the request.
454 * @property {string|boolean} [validation] Possible values: `"md5"`,
455 * `"crc32c"`, or `false`. By default, data integrity is validated with a
456 * CRC32c checksum. You may use MD5 if preferred, but that hash is not
457 * supported for composite objects. An error will be raised if MD5 is
458 * specified but is not available. You may also choose to skip validation
459 * completely, however this is **not recommended**.
460 * @property {number} [start] A byte offset to begin the file's download
461 * from. Default is 0. NOTE: Byte ranges are inclusive; that is,
462 * `options.start = 0` and `options.end = 999` represent the first 1000
463 * bytes in a file or object. NOTE: when specifying a byte range, data
464 * integrity is not available.
465 * @property {number} [end] A byte offset to stop reading the file at.
466 * NOTE: Byte ranges are inclusive; that is, `options.start = 0` and
467 * `options.end = 999` represent the first 1000 bytes in a file or object.
468 * NOTE: when specifying a byte range, data integrity is not available.
469 * @property {boolean} [decompress=true] Disable auto decompression of the
470 * received data. By default this option is set to `true`.
471 * Applicable in cases where the data was uploaded with
472 * `gzip: true` option. See {@link File#createWriteStream}.
473 */
474 /**
475 * Create a readable stream to read the contents of the remote file. It can be
476 * piped to a writable stream or listened to for 'data' events to read a
477 * file's contents.
478 *
479 * In the unlikely event there is a mismatch between what you downloaded and
480 * the version in your Bucket, your error handler will receive an error with
481 * code "CONTENT_DOWNLOAD_MISMATCH". If you receive this error, the best
482 * recourse is to try downloading the file again.
483 *
484 * NOTE: Readable streams will emit the `end` event when the file is fully
485 * downloaded.
486 *
487 * @param {CreateReadStreamOptions} [options] Configuration options.
488 * @returns {ReadableStream}
489 *
490 * @example
491 * ```
492 * //-
493 * // <h4>Downloading a File</h4>
494 * //
495 * // The example below demonstrates how we can reference a remote file, then
496 * // pipe its contents to a local file. This is effectively creating a local
497 * // backup of your remote data.
498 * //-
499 * const {Storage} = require('@google-cloud/storage');
500 * const storage = new Storage();
501 * const bucket = storage.bucket('my-bucket');
502 *
503 * const fs = require('fs');
504 * const remoteFile = bucket.file('image.png');
505 * const localFilename = '/Users/stephen/Photos/image.png';
506 *
507 * remoteFile.createReadStream()
508 * .on('error', function(err) {})
509 * .on('response', function(response) {
510 * // Server connected and responded with the specified status and headers.
511 * })
512 * .on('end', function() {
513 * // The file is fully downloaded.
514 * })
515 * .pipe(fs.createWriteStream(localFilename));
516 *
517 * //-
518 * // To limit the downloaded data to only a byte range, pass an options
519 * // object.
520 * //-
521 * const logFile = myBucket.file('access_log');
522 * logFile.createReadStream({
523 * start: 10000,
524 * end: 20000
525 * })
526 * .on('error', function(err) {})
527 * .pipe(fs.createWriteStream('/Users/stephen/logfile.txt'));
528 *
529 * //-
530 * // To read a tail byte range, specify only `options.end` as a negative
531 * // number.
532 * //-
533 * const logFile = myBucket.file('access_log');
534 * logFile.createReadStream({
535 * end: -100
536 * })
537 * .on('error', function(err) {})
538 * .pipe(fs.createWriteStream('/Users/stephen/logfile.txt'));
539 * ```
540 */
541 createReadStream(options?: CreateReadStreamOptions): Readable;
542 createResumableUpload(options?: CreateResumableUploadOptions): Promise<CreateResumableUploadResponse>;
543 createResumableUpload(options: CreateResumableUploadOptions, callback: CreateResumableUploadCallback): void;
544 createResumableUpload(callback: CreateResumableUploadCallback): void;
545 /**
546 * @typedef {object} CreateWriteStreamOptions Configuration options for File#createWriteStream().
547 * @property {string} [contentType] Alias for
548 * `options.metadata.contentType`. If set to `auto`, the file name is used
549 * to determine the contentType.
550 * @property {string|boolean} [gzip] If true, automatically gzip the file.
551 * If set to `auto`, the contentType is used to determine if the file
552 * should be gzipped. This will set `options.metadata.contentEncoding` to
553 * `gzip` if necessary.
554 * @property {object} [metadata] See the examples below or
555 * {@link https://cloud.google.com/storage/docs/json_api/v1/objects/insert#request_properties_JSON| Objects: insert request body}
556 * for more details.
557 * @property {number} [offset] The starting byte of the upload stream, for
558 * resuming an interrupted upload. Defaults to 0.
559 * @property {string} [predefinedAcl] Apply a predefined set of access
560 * controls to this object.
561 *
562 * Acceptable values are:
563 * - **`authenticatedRead`** - Object owner gets `OWNER` access, and
564 * `allAuthenticatedUsers` get `READER` access.
565 *
566 * - **`bucketOwnerFullControl`** - Object owner gets `OWNER` access, and
567 * project team owners get `OWNER` access.
568 *
569 * - **`bucketOwnerRead`** - Object owner gets `OWNER` access, and project
570 * team owners get `READER` access.
571 *
572 * - **`private`** - Object owner gets `OWNER` access.
573 *
574 * - **`projectPrivate`** - Object owner gets `OWNER` access, and project
575 * team members get access according to their roles.
576 *
577 * - **`publicRead`** - Object owner gets `OWNER` access, and `allUsers`
578 * get `READER` access.
579 * @property {boolean} [private] Make the uploaded file private. (Alias for
580 * `options.predefinedAcl = 'private'`)
581 * @property {boolean} [public] Make the uploaded file public. (Alias for
582 * `options.predefinedAcl = 'publicRead'`)
583 * @property {boolean} [resumable] Force a resumable upload. NOTE: When
584 * working with streams, the file format and size is unknown until it's
585 * completely consumed. Because of this, it's best for you to be explicit
586 * for what makes sense given your input.
587 * @property {number} [timeout=60000] Set the HTTP request timeout in
588 * milliseconds. This option is not available for resumable uploads.
589 * Default: `60000`
590 * @property {string} [uri] The URI for an already-created resumable
591 * upload. See {@link File#createResumableUpload}.
592 * @property {string} [userProject] The ID of the project which will be
593 * billed for the request.
594 * @property {string|boolean} [validation] Possible values: `"md5"`,
595 * `"crc32c"`, or `false`. By default, data integrity is validated with a
596 * CRC32c checksum. You may use MD5 if preferred, but that hash is not
597 * supported for composite objects. An error will be raised if MD5 is
598 * specified but is not available. You may also choose to skip validation
599 * completely, however this is **not recommended**. In addition to specifying
600 * validation type, providing `metadata.crc32c` or `metadata.md5Hash` will
601 * cause the server to perform validation in addition to client validation.
602 * NOTE: Validation is automatically skipped for objects that were
603 * uploaded using the `gzip` option and have already compressed content.
604 */
605 /**
606 * Create a writable stream to overwrite the contents of the file in your
607 * bucket.
608 *
609 * A File object can also be used to create files for the first time.
610 *
611 * Resumable uploads are automatically enabled and must be shut off explicitly
612 * by setting `options.resumable` to `false`.
613 *
614 *
615 * <p class="notice">
616 * There is some overhead when using a resumable upload that can cause
617 * noticeable performance degradation while uploading a series of small
618 * files. When uploading files less than 10MB, it is recommended that the
619 * resumable feature is disabled.
620 * </p>
621 *
622 * NOTE: Writable streams will emit the `finish` event when the file is fully
623 * uploaded.
624 *
625 * See {@link https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload| Upload Options (Simple or Resumable)}
626 * See {@link https://cloud.google.com/storage/docs/json_api/v1/objects/insert| Objects: insert API Documentation}
627 *
628 * @param {CreateWriteStreamOptions} [options] Configuration options.
629 * @returns {WritableStream}
630 *
631 * @example
632 * ```
633 * const fs = require('fs');
634 * const {Storage} = require('@google-cloud/storage');
635 * const storage = new Storage();
636 * const myBucket = storage.bucket('my-bucket');
637 *
638 * const file = myBucket.file('my-file');
639 *
640 * //-
641 * // <h4>Uploading a File</h4>
642 * //
643 * // Now, consider a case where we want to upload a file to your bucket. You
644 * // have the option of using {@link Bucket#upload}, but that is just
645 * // a convenience method which will do the following.
646 * //-
647 * fs.createReadStream('/Users/stephen/Photos/birthday-at-the-zoo/panda.jpg')
648 * .pipe(file.createWriteStream())
649 * .on('error', function(err) {})
650 * .on('finish', function() {
651 * // The file upload is complete.
652 * });
653 *
654 * //-
655 * // <h4>Uploading a File with gzip compression</h4>
656 * //-
657 * fs.createReadStream('/Users/stephen/site/index.html')
658 * .pipe(file.createWriteStream({ gzip: true }))
659 * .on('error', function(err) {})
660 * .on('finish', function() {
661 * // The file upload is complete.
662 * });
663 *
664 * //-
665 * // Downloading the file with `createReadStream` will automatically decode
666 * // the file.
667 * //-
668 *
669 * //-
670 * // <h4>Uploading a File with Metadata</h4>
671 * //
672 * // One last case you may run into is when you want to upload a file to your
673 * // bucket and set its metadata at the same time. Like above, you can use
674 * // {@link Bucket#upload} to do this, which is just a wrapper around
675 * // the following.
676 * //-
677 * fs.createReadStream('/Users/stephen/Photos/birthday-at-the-zoo/panda.jpg')
678 * .pipe(file.createWriteStream({
679 * metadata: {
680 * contentType: 'image/jpeg',
681 * metadata: {
682 * custom: 'metadata'
683 * }
684 * }
685 * }))
686 * .on('error', function(err) {})
687 * .on('finish', function() {
688 * // The file upload is complete.
689 * });
690 * ```
691 */
692 createWriteStream(options?: CreateWriteStreamOptions): Writable;
693 /**
694 * Delete the object.
695 *
696 * @param {function=} callback - The callback function.
697 * @param {?error} callback.err - An error returned while making this request.
698 * @param {object} callback.apiResponse - The full API response.
699 */
700 delete(options?: DeleteOptions): Promise<[r.Response]>;
701 delete(options: DeleteOptions, callback: DeleteCallback): void;
702 delete(callback: DeleteCallback): void;
703 download(options?: DownloadOptions): Promise<DownloadResponse>;
704 download(options: DownloadOptions, callback: DownloadCallback): void;
705 download(callback: DownloadCallback): void;
706 /**
707 * The Storage API allows you to use a custom key for server-side encryption.
708 *
709 * See {@link https://cloud.google.com/storage/docs/encryption#customer-supplied| Customer-supplied Encryption Keys}
710 *
711 * @param {string|buffer} encryptionKey An AES-256 encryption key.
712 * @returns {File}
713 *
714 * @example
715 * ```
716 * const crypto = require('crypto');
717 * const {Storage} = require('@google-cloud/storage');
718 * const storage = new Storage();
719 * const myBucket = storage.bucket('my-bucket');
720 *
721 * const encryptionKey = crypto.randomBytes(32);
722 *
723 * const fileWithCustomEncryption = myBucket.file('my-file');
724 * fileWithCustomEncryption.setEncryptionKey(encryptionKey);
725 *
726 * const fileWithoutCustomEncryption = myBucket.file('my-file');
727 *
728 * fileWithCustomEncryption.save('data', function(err) {
729 * // Try to download with the File object that hasn't had
730 * // `setEncryptionKey()` called:
731 * fileWithoutCustomEncryption.download(function(err) {
732 * // We will receive an error:
733 * // err.message === 'Bad Request'
734 *
735 * // Try again with the File object we called `setEncryptionKey()` on:
736 * fileWithCustomEncryption.download(function(err, contents) {
737 * // contents.toString() === 'data'
738 * });
739 * });
740 * });
741 *
742 * ```
743 * @example <caption>include:samples/encryption.js</caption>
744 * region_tag:storage_upload_encrypted_file
745 * Example of uploading an encrypted file:
746 *
747 * @example <caption>include:samples/encryption.js</caption>
748 * region_tag:storage_download_encrypted_file
749 * Example of downloading an encrypted file:
750 */
751 setEncryptionKey(encryptionKey: string | Buffer): this;
752 getExpirationDate(): Promise<GetExpirationDateResponse>;
753 getExpirationDate(callback: GetExpirationDateCallback): void;
754 generateSignedPostPolicyV2(options: GenerateSignedPostPolicyV2Options): Promise<GenerateSignedPostPolicyV2Response>;
755 generateSignedPostPolicyV2(options: GenerateSignedPostPolicyV2Options, callback: GenerateSignedPostPolicyV2Callback): void;
756 generateSignedPostPolicyV2(callback: GenerateSignedPostPolicyV2Callback): void;
757 generateSignedPostPolicyV4(options: GenerateSignedPostPolicyV4Options): Promise<GenerateSignedPostPolicyV4Response>;
758 generateSignedPostPolicyV4(options: GenerateSignedPostPolicyV4Options, callback: GenerateSignedPostPolicyV4Callback): void;
759 generateSignedPostPolicyV4(callback: GenerateSignedPostPolicyV4Callback): void;
760 getSignedUrl(cfg: GetSignedUrlConfig): Promise<GetSignedUrlResponse>;
761 getSignedUrl(cfg: GetSignedUrlConfig, callback: GetSignedUrlCallback): void;
762 isPublic(): Promise<IsPublicResponse>;
763 isPublic(callback: IsPublicCallback): void;
764 makePrivate(options?: MakeFilePrivateOptions): Promise<MakeFilePrivateResponse>;
765 makePrivate(callback: MakeFilePrivateCallback): void;
766 makePrivate(options: MakeFilePrivateOptions, callback: MakeFilePrivateCallback): void;
767 makePublic(): Promise<MakeFilePublicResponse>;
768 makePublic(callback: MakeFilePublicCallback): void;
769 /**
770 * The public URL of this File
771 * Use {@link File#makePublic} to enable anonymous access via the returned URL.
772 *
773 * @returns {string}
774 *
775 * @example
776 * ```
777 * const {Storage} = require('@google-cloud/storage');
778 * const storage = new Storage();
779 * const bucket = storage.bucket('albums');
780 * const file = bucket.file('my-file');
781 *
782 * // publicUrl will be "https://storage.googleapis.com/albums/my-file"
783 * const publicUrl = file.publicUrl();
784 * ```
785 */
786 publicUrl(): string;
787 move(destination: string | Bucket | File, options?: MoveOptions): Promise<MoveResponse>;
788 move(destination: string | Bucket | File, callback: MoveCallback): void;
789 move(destination: string | Bucket | File, options: MoveOptions, callback: MoveCallback): void;
790 rename(destinationFile: string | File, options?: RenameOptions): Promise<RenameResponse>;
791 rename(destinationFile: string | File, callback: RenameCallback): void;
792 rename(destinationFile: string | File, options: RenameOptions, callback: RenameCallback): void;
793 request(reqOpts: DecorateRequestOptions): Promise<[ResponseBody, Metadata]>;
794 request(reqOpts: DecorateRequestOptions, callback: BodyResponseCallback): void;
795 rotateEncryptionKey(options?: RotateEncryptionKeyOptions): Promise<RotateEncryptionKeyResponse>;
796 rotateEncryptionKey(callback: RotateEncryptionKeyCallback): void;
797 rotateEncryptionKey(options: RotateEncryptionKeyOptions, callback: RotateEncryptionKeyCallback): void;
798 save(data: string | Buffer, options?: SaveOptions): Promise<void>;
799 save(data: string | Buffer, callback: SaveCallback): void;
800 save(data: string | Buffer, options: SaveOptions, callback: SaveCallback): void;
801 setMetadata(metadata: Metadata, options?: SetMetadataOptions): Promise<SetMetadataResponse>;
802 setMetadata(metadata: Metadata, callback: MetadataCallback): void;
803 setMetadata(metadata: Metadata, options: SetMetadataOptions, callback: MetadataCallback): void;
804 setStorageClass(storageClass: string, options?: SetStorageClassOptions): Promise<SetStorageClassResponse>;
805 setStorageClass(storageClass: string, options: SetStorageClassOptions, callback: SetStorageClassCallback): void;
806 setStorageClass(storageClass: string, callback?: SetStorageClassCallback): void;
807 /**
808 * Set a user project to be billed for all requests made from this File
809 * object.
810 *
811 * @param {string} userProject The user project.
812 *
813 * @example
814 * ```
815 * const {Storage} = require('@google-cloud/storage');
816 * const storage = new Storage();
817 * const bucket = storage.bucket('albums');
818 * const file = bucket.file('my-file');
819 *
820 * file.setUserProject('grape-spaceship-123');
821 * ```
822 */
823 setUserProject(userProject: string): void;
824 /**
825 * This creates a resumable-upload upload stream.
826 *
827 * @param {Duplexify} stream - Duplexify stream of data to pipe to the file.
828 * @param {object=} options - Configuration object.
829 *
830 * @private
831 */
832 startResumableUpload_(dup: Duplexify, options: CreateResumableUploadOptions): void;
833 /**
834 * Takes a readable stream and pipes it to a remote file. Unlike
835 * `startResumableUpload_`, which uses the resumable upload technique, this
836 * method uses a simple upload (all or nothing).
837 *
838 * @param {Duplexify} dup - Duplexify stream of data to pipe to the file.
839 * @param {object=} options - Configuration object.
840 *
841 * @private
842 */
843 startSimpleUpload_(dup: Duplexify, options?: CreateWriteStreamOptions): void;
844 disableAutoRetryConditionallyIdempotent_(coreOpts: any, methodType: AvailableServiceObjectMethods, localPreconditionOptions?: PreconditionOptions): void;
845 private getBufferFromReadable;
846}
847/**
848 * Reference to the {@link File} class.
849 * @name module:@google-cloud/storage.File
850 * @see File
851 */
852export { File };
853
\No newline at end of file