@@ -23,6 +23,7 @@ import { DriveFile } from '../../src/driver_file.js'
2323import { DriveDirectory } from '../../src/drive_directory.js'
2424import type {
2525 WriteOptions ,
26+ CopyMoveOptions ,
2627 ObjectMetaData ,
2728 DriverContract ,
2829 SignedURLOptions ,
@@ -381,58 +382,75 @@ export class GCSDriver implements DriverContract {
381382 /**
382383 * Copies the source file to the destination. Both paths must
383384 * be within the root location.
385+ *
386+ * Use the "bucket" option to copy the file to a different bucket.
384387 */
385- async copy ( source : string , destination : string , options ?: WriteOptions ) : Promise < void > {
388+ async copy ( source : string , destination : string , options ?: CopyMoveOptions ) : Promise < void > {
389+ const { bucket : destinationBucket , ...writeOptions } = options || { }
390+ const targetBucket = destinationBucket || this . options . bucket
391+
386392 debug (
387393 'copying file from %s:%s to %s:%s' ,
388394 this . options . bucket ,
389395 source ,
390- this . options . bucket ,
396+ targetBucket ,
391397 destination
392398 )
393- const bucket = this . #storage . bucket ( this . options . bucket )
394- options = options || { }
399+
400+ const sourceBucket = this . #storage . bucket ( this . options . bucket )
395401
396402 /**
397403 * Copy visibility from the source file to the
398404 * desintation when no inline visibility is
399405 * defined and not using usingUniformAcl
400406 */
401- if ( ! options . visibility && ! this . #usingUniformAcl) {
402- const [ isFilePublic ] = await bucket . file ( source ) . isPublic ( )
403- options . visibility = isFilePublic ? 'public' : 'private'
407+ if ( ! writeOptions . visibility && ! this . #usingUniformAcl) {
408+ const [ isFilePublic ] = await sourceBucket . file ( source ) . isPublic ( )
409+ writeOptions . visibility = isFilePublic ? 'public' : 'private'
404410 }
405411
406- await bucket . file ( source ) . copy ( destination , this . #getSaveOptions( options ) )
412+ const target = destinationBucket
413+ ? this . #storage. bucket ( destinationBucket ) . file ( destination )
414+ : destination
415+
416+ await sourceBucket . file ( source ) . copy ( target , this . #getSaveOptions( writeOptions ) )
407417 }
408418
409419 /**
410420 * Moves the source file to the destination. Both paths must
411421 * be within the root location.
422+ *
423+ * Use the "bucket" option to move the file to a different bucket.
412424 */
413- async move ( source : string , destination : string , options ?: WriteOptions ) : Promise < void > {
425+ async move ( source : string , destination : string , options ?: CopyMoveOptions ) : Promise < void > {
426+ const { bucket : destinationBucket , ...writeOptions } = options || { }
427+ const targetBucket = destinationBucket || this . options . bucket
428+
414429 debug (
415430 'moving file from %s:%s to %s:%s' ,
416431 this . options . bucket ,
417432 source ,
418- this . options . bucket ,
433+ targetBucket ,
419434 destination
420435 )
421436
422- const bucket = this . #storage. bucket ( this . options . bucket )
423- options = options || { }
437+ const sourceBucket = this . #storage. bucket ( this . options . bucket )
424438
425439 /**
426440 * Copy visibility from the source file to the
427441 * desintation when no inline visibility is
428442 * defined and not using usingUniformAcl
429443 */
430- if ( ! options . visibility && ! this . #usingUniformAcl) {
431- const [ isFilePublic ] = await bucket . file ( source ) . isPublic ( )
432- options . visibility = isFilePublic ? 'public' : 'private'
444+ if ( ! writeOptions . visibility && ! this . #usingUniformAcl) {
445+ const [ isFilePublic ] = await sourceBucket . file ( source ) . isPublic ( )
446+ writeOptions . visibility = isFilePublic ? 'public' : 'private'
433447 }
434448
435- await bucket . file ( source ) . move ( destination , this . #getSaveOptions( options ) )
449+ const target = destinationBucket
450+ ? this . #storage. bucket ( destinationBucket ) . file ( destination )
451+ : destination
452+
453+ await sourceBucket . file ( source ) . move ( target , this . #getSaveOptions( writeOptions ) )
436454 }
437455
438456 /**
0 commit comments