UNPKG

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