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

Refactor out BufferStream #179

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions lib/common/bufferstream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var stream = require('stream');
var nodeutil = require('util');

/**
* Readable stream implementation to stream the given buffer.
*
* @constructor
*
* @param {buffer} buffer - The buffer to stream.
*
* @private
*/
function BufferStream(buffer) {
stream.Readable.call(this);
this.data = buffer;
}

nodeutil.inherits(BufferStream, stream.Readable);

/**
* Push the provided buffer to the stream.
* @private
*/
BufferStream.prototype._read = function() {
this.push(this.data);
this.push(null);
};

module.exports = BufferStream;
33 changes: 6 additions & 27 deletions lib/storage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

var crypto = require('crypto');
var duplexify = require('duplexify');
var nodeutil = require('util');
var stream = require('stream');
var uuid = require('node-uuid');

/**
Expand All @@ -38,6 +36,12 @@ var conn = require('../common/connection.js');
*/
var util = require('../common/util.js');

/**
* @type module:common/bufferstream
* @private
*/
var BufferStream = require('../common/bufferstream.js');

/**
* Required scopes for Google Cloud Storage API.
* @const {array}
Expand All @@ -57,31 +61,6 @@ var STORAGE_BASE_URL = 'https://www.googleapis.com/storage/v1/b';
*/
var STORAGE_UPLOAD_BASE_URL = 'https://www.googleapis.com/upload/storage/v1/b';

/**
* Readable stream implementation to stream the given buffer.
*
* @constructor
*
* @param {buffer} buffer - The buffer to stream.
*
* @private
*/
function BufferStream(buffer) {
stream.Readable.call(this);
this.data = buffer;
}

nodeutil.inherits(BufferStream, stream.Readable);

/**
* Push the provided buffer to the stream.
* @private
*/
BufferStream.prototype._read = function() {
this.push(this.data);
this.push(null);
};

/**
* Google Cloud Storage allows you to store data on Google infrastructure. See
* the guide on {@link https://developers.google.com/storage} to create a
Expand Down