@@ -249,6 +249,10 @@ export interface MoveOptions {
249249 userProject ?: string ;
250250}
251251
252+ export type RenameOptions = MoveOptions ;
253+ export type RenameResponse = MoveResponse ;
254+ export type RenameCallback = MoveCallback ;
255+
252256export type RotateEncryptionKeyOptions = string | Buffer | EncryptionKeyOptions ;
253257
254258export interface EncryptionKeyOptions {
@@ -3233,6 +3237,114 @@ class File extends ServiceObject<File> {
32333237 } ) ;
32343238 }
32353239
3240+ rename (
3241+ destinationFile : string | File ,
3242+ options ?: RenameOptions
3243+ ) : Promise < RenameResponse > ;
3244+ rename ( destinationFile : string | File , callback : RenameCallback ) : void ;
3245+ rename (
3246+ destinationFile : string | File ,
3247+ options : RenameOptions ,
3248+ callback : RenameCallback
3249+ ) : void ;
3250+ /**
3251+ * @typedef {array } RenameResponse
3252+ * @property {File } 0 The destination File.
3253+ * @property {object } 1 The full API response.
3254+ */
3255+ /**
3256+ * @callback RenameCallback
3257+ * @param {?Error } err Request error, if any.
3258+ * @param {?File } destinationFile The destination File.
3259+ * @param {object } apiResponse The full API response.
3260+ */
3261+ /**
3262+ * @typedef {object } RenameOptions Configuration options for File#move(). See an
3263+ * [Object
3264+ * resource](https://cloud.google.com/storage/docs/json_api/v1/objects#resource).
3265+ * @param {string } [userProject] The ID of the project which will be
3266+ * billed for the request.
3267+ */
3268+ /**
3269+ * Rename this file.
3270+ *
3271+ * **Warning**:
3272+ * There is currently no atomic `rename` method in the Cloud Storage API,
3273+ * so this method is an alias of {@link File#move}, which in turn is a
3274+ * composition of {@link File#copy} (to the new location) and
3275+ * {@link File#delete} (from the old location). While
3276+ * unlikely, it is possible that an error returned to your callback could be
3277+ * triggered from either one of these API calls failing, which could leave a
3278+ * duplicate file lingering. The error message will indicate what operation
3279+ * has failed.
3280+ *
3281+ * @param {string|File } destinationFile Destination file.
3282+ * @param {RenameCallback } [callback] Callback function.
3283+ * @returns {Promise<RenameResponse> }
3284+ *
3285+ * @example
3286+ * const {Storage} = require('@google-cloud/storage');
3287+ * const storage = new Storage();
3288+ *
3289+ * //-
3290+ * // You can pass in a string or a File object.
3291+ * //
3292+ * // For all of the below examples, assume we are working with the following
3293+ * // Bucket and File objects.
3294+ * //-
3295+ *
3296+ * const bucket = storage.bucket('my-bucket');
3297+ * const file = bucket.file('my-image.png');
3298+ *
3299+ * //-
3300+ * // You can pass in a string for the destinationFile.
3301+ * //-
3302+ * file.rename('renamed-image.png', function(err, renamedFile, apiResponse) {
3303+ * // `my-bucket` no longer contains:
3304+ * // - "my-image.png"
3305+ * // but contains instead:
3306+ * // - "renamed-image.png"
3307+ *
3308+ * // `renamedFile` is an instance of a File object that refers to your
3309+ * // renamed file.
3310+ * });
3311+ *
3312+ * //-
3313+ * // You can pass in a File object.
3314+ * //-
3315+ * const anotherFile = anotherBucket.file('my-awesome-image.png');
3316+ *
3317+ * file.rename(anotherFile, function(err, renamedFile, apiResponse) {
3318+ * // `my-bucket` no longer contains:
3319+ * // - "my-image.png"
3320+ *
3321+ * // Note:
3322+ * // The `renamedFile` parameter is equal to `anotherFile`.
3323+ * });
3324+ *
3325+ * //-
3326+ * // If the callback is omitted, we'll return a Promise.
3327+ * //-
3328+ * file.rename('my-renamed-image.png').then(function(data) {
3329+ * const renamedFile = data[0];
3330+ * const apiResponse = data[1];
3331+ * });
3332+ */
3333+ rename (
3334+ destinationFile : string | File ,
3335+ optionsOrCallback ?: RenameOptions | RenameCallback ,
3336+ callback ?: RenameCallback
3337+ ) : Promise < RenameResponse > | void {
3338+ const options =
3339+ typeof optionsOrCallback === 'object' ? optionsOrCallback : { } ;
3340+ callback =
3341+ typeof optionsOrCallback === 'function' ? optionsOrCallback : callback ;
3342+
3343+ callback = callback || util . noop ;
3344+
3345+ this . move ( destinationFile , options , callback ) ;
3346+ }
3347+
32363348 request ( reqOpts : DecorateRequestOptions ) : Promise < [ ResponseBody , Metadata ] > ;
32373349 request (
32383350 reqOpts : DecorateRequestOptions ,
0 commit comments