Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage: file.copy, file.move(, others?) don't accept "gs://" URLs #1395

Closed
zbjornson opened this issue Jun 26, 2016 · 3 comments
Closed

Storage: file.copy, file.move(, others?) don't accept "gs://" URLs #1395

zbjornson opened this issue Jun 26, 2016 · 3 comments
Assignees
Labels
api: storage Issues related to the Cloud Storage API.

Comments

@zbjornson
Copy link
Contributor

zbjornson commented Jun 26, 2016

I was rather surprised when this command:

bucket.file("foo").copy("gs://otherbucket/something", cb)

created an object in the original bucket in a "gs:/" subdirectory. I see how to do what I want by passing a file or bucket instead of a string, but it seems like this could easily be supported with something like this:

--- lib/storage/file.js
+++ lib/storage/file.js
@@ File.prototype.copy = function(destination, callback) { @@
  if (is.string(destination)) {
+   if (destination.startsWith("gs://") {
+     var parsed = /^gs\:\/\/([a-z_\.\-]+)\/(.+)$/.exec(destination);
+     // assert parsed.length === 3
+     destBucket = parsed[1];
+     destName = parsed[2];
+   } else {
+     destBucket = this.bucket;
+     destName = destination;
+   }
-   destBucket = this.bucket;
-   destName = destination;
  } else if (destination.constructor &&

(Happy to make a PR with something like that.)

@stephenplusplus
Copy link
Contributor

I'm totally cool with that. A PR would be great! Only note is to use indexOf instead of startsWith since we still support 0.12. Thanks!

@stephenplusplus stephenplusplus added enhancement api: storage Issues related to the Cloud Storage API. labels Jun 26, 2016
@zbjornson
Copy link
Contributor Author

Thanks. Heading out of town, probably won't get to a PR until ~10 July.

@stephenplusplus
Copy link
Contributor

Sounds good, safe travels!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API.
Projects
None yet
Development

No branches or pull requests

2 participants