diff --git a/lib/common/bufferstream.js b/lib/common/bufferstream.js new file mode 100644 index 00000000000..22f50dbb739 --- /dev/null +++ b/lib/common/bufferstream.js @@ -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; diff --git a/lib/storage/index.js b/lib/storage/index.js index 6330947d549..e3f0d1e77ab 100644 --- a/lib/storage/index.js +++ b/lib/storage/index.js @@ -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'); /** @@ -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} @@ -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