@@ -122,6 +122,23 @@ export interface CopyOptions {
122122 userProject ?: string ;
123123}
124124
125+ /**
126+ * @typedef {array } DownloadResponse
127+ * @property [0] The contents of a File.
128+ */
129+ export type DownloadResponse = [ Buffer ] ;
130+
131+ /**
132+ * @callback DownloadCallback
133+ * @param err Request error, if any.
134+ * @param contents The contents of a File.
135+ */
136+ export type DownloadCallback = ( err : Error | undefined , contents : Buffer ) => void ;
137+
138+ export interface DownloadOptions extends CreateReadStreamOptions {
139+ destination ?: string ;
140+ }
141+
125142interface CopyQuery {
126143 sourceGeneration ?: number ;
127144 rewriteToken ?: string ;
@@ -1306,15 +1323,6 @@ class File extends ServiceObject {
13061323 ( this . parent as ServiceObject ) . delete . call ( this , options , callback ) ;
13071324 }
13081325
1309- /**
1310- * @typedef {array } DownloadResponse
1311- * @property {object } [0] The contents of a File.
1312- */
1313- /**
1314- * @callback DownloadCallback
1315- * @param {?Error } err Request error, if any.
1316- * @param {buffer } [contents] The contents of a File.
1317- */
13181326 /**
13191327 * Convenience method to download a file into memory or to a local
13201328 * destination.
@@ -1368,13 +1376,21 @@ class File extends ServiceObject {
13681376 * region_tag:storage_download_file_requester_pays
13691377 * Example of downloading a file where the requester pays:
13701378 */
1371- download ( options ?, callback ?) {
1372- if ( is . fn ( options ) ) {
1373- callback = options ;
1379+ download ( options ?: DownloadOptions ) : Promise < DownloadResponse > ;
1380+ download ( options : DownloadOptions , callback : DownloadCallback ) : void ;
1381+ download ( callback : DownloadCallback ) : void ;
1382+ download (
1383+ optionsOrCallback ?: DownloadOptions | DownloadCallback ,
1384+ callback ?: DownloadCallback ) : Promise < DownloadResponse > | void {
1385+ let options : DownloadOptions ;
1386+ if ( is . fn ( optionsOrCallback ) ) {
1387+ callback = optionsOrCallback as DownloadCallback ;
13741388 options = { } ;
1389+ } else {
1390+ options = optionsOrCallback as DownloadOptions ;
13751391 }
13761392
1377- callback = once ( callback ) ;
1393+ callback = once ( callback as DownloadCallback ) ;
13781394
13791395 const destination = options . destination ;
13801396 delete options . destination ;
0 commit comments