Comparing version 1.1.0 to 1.2.0
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { CreateReadStreamOptions, CreateWriteStreamOptions, DownloadOptions, DownloadResponse, FileOptions, GetSignedUrlConfig, GetSignedUrlResponse, SaveOptions } from '@google-cloud/storage'; | ||
import { CreateReadStreamOptions, CreateWriteStreamOptions, DownloadOptions, DownloadResponse, FileOptions, GetSignedUrlConfig, GetSignedUrlResponse, SaveOptions, CopyOptions, CopyResponse } from '@google-cloud/storage'; | ||
import MockBucket, { IBucket } from './MockBucket'; | ||
@@ -67,3 +67,10 @@ import { Readable, Writable } from 'stream'; | ||
save(data: string | Buffer, options?: SaveOptions): Promise<void>; | ||
/** | ||
* Copies the current file to the specified destination. | ||
* @param destination The destination can be a string (file name), Bucket, or File object. | ||
* @param options Optional CopyOptions. | ||
* @returns A promise that resolves to the CopyResponse. | ||
*/ | ||
copy(destination: string | MockBucket | MockFile, options?: CopyOptions): Promise<CopyResponse>; | ||
} | ||
export default MockFile; |
@@ -224,2 +224,45 @@ "use strict"; | ||
}; | ||
/** | ||
* Copies the current file to the specified destination. | ||
* @param destination The destination can be a string (file name), Bucket, or File object. | ||
* @param options Optional CopyOptions. | ||
* @returns A promise that resolves to the CopyResponse. | ||
*/ | ||
MockFile.prototype.copy = function (destination, options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var targetBucket, targetFileName, contents, metadata, newMetadata, newFile; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (typeof destination === 'string') { | ||
targetBucket = this.bucket; | ||
targetFileName = destination; | ||
} | ||
else if ('name' in destination && 'file' in destination) { | ||
targetBucket = destination; | ||
targetFileName = this.name; | ||
} | ||
else if ('name' in destination) { | ||
targetBucket = destination.bucket; | ||
targetFileName = destination.name; | ||
} | ||
else { | ||
throw new Error('Invalid destination type'); | ||
} | ||
return [4 /*yield*/, this.download()]; | ||
case 1: | ||
contents = (_a.sent())[0]; | ||
return [4 /*yield*/, this.getMetadata()]; | ||
case 2: | ||
metadata = (_a.sent())[0]; | ||
newMetadata = __assign(__assign({}, metadata), options === null || options === void 0 ? void 0 : options.metadata); | ||
newFile = targetBucket.file(targetFileName); | ||
return [4 /*yield*/, newFile.save(contents, { metadata: newMetadata })]; | ||
case 3: | ||
_a.sent(); | ||
return [2 /*return*/, [newFile, newMetadata]]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return MockFile; | ||
@@ -226,0 +269,0 @@ }()); |
{ | ||
"name": "mock-gcs", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Mock implementation of the Google Cloud Storage SDK.", | ||
@@ -5,0 +5,0 @@ "url": "https://github.com/aldipermanaetikaputra/mock-gcs", |
@@ -15,2 +15,3 @@ # mock-gcs | ||
- `bucket.cloudStorageURI` | ||
- `file.copy()` (promise-based only) | ||
- `file.delete()` (promise-based only) | ||
@@ -17,0 +18,0 @@ - `file.exists()` (promise-based only) |
35982
569
178