Skip to content

Commit a396eb6

Browse files
readme: update with examples from storage.
1 parent fd12ad0 commit a396eb6

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

README.md

+17-10
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,32 @@ If you don't have a bucket already, follow the steps of the [Creating a Bucket g
8383
See the [gcloud-node Storage API documentation][gcloud-storage-docs] to learn how to connect to Cloud Storage using this library.
8484

8585
```js
86+
var fs = require('fs');
8687
var gcloud = require('gcloud');
87-
var bucket;
88+
var storage;
8889

8990
// From Google Compute Engine:
90-
bucket = gcloud.storage.bucket({
91-
projectId: 'my-project',
92-
bucketName: 'my-bucket'
91+
storage = gcloud.storage({
92+
projectId: 'my-project'
9393
});
9494

9595
// Or from elsewhere:
96-
bucket = gcloud.storage.bucket({
97-
projectId: 'my-project',
96+
storage = gcloud.storage({
9897
keyFilename: '/path/to/keyfile.json',
99-
bucketName: 'my-bucket'
98+
projectId: 'my-project'
10099
});
101100

102-
bucket.write('demo.txt', 'Hello World', function(err) {
103-
console.log(err || 'Created demo.txt');
104-
});
101+
// Create a new bucket.
102+
storage.createBucket('my-new-bucket', function(err, bucket) {});
103+
104+
// Reference an existing bucket.
105+
var bucket = storage.bucket('my-bucket');
106+
107+
// Upload a local file to a new file to be created in your bucket.
108+
fs.createReadStream('/local/file.txt').pipe(bucket.file('file.txt'));
109+
110+
// Download a remote file to a new local file.
111+
bucket.file('photo.jpg').pipe(fs.createWriteStream('/local/photo.jpg'));
105112
```
106113

107114
## Google Cloud Pub/Sub (Alpha)

0 commit comments

Comments
 (0)