Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Rodrigues committed Oct 1, 2012
2 parents 1a559f0 + b9fe17d commit d4d3ca0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 39 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2012.09.18 Version 0.6.4
* Multiple Bugfixes around blob streaming

2012.09.09 Version 0.6.3
* Fixing issue with xml2js

2012.08.15 Version 0.6.2
* Multiple Bugfixes

Expand Down
17 changes: 12 additions & 5 deletions lib/cli/iaas/upload/bufferStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
* Creates a writeStream-like object that accumulates results to a buffer
*
*/
var events = require('events');

var createBufferWriteStream =
exports.createBufferWriteStream =
function(callback) {

var ret = {writeable : true};
var ret = new events.EventEmitter();
ret.writeable = true;
var buffers = [];
ret.write = function(buffer, encoding) {
if (typeof buffer === 'string' || (encoding && encoding !== 'binary')) {
Expand All @@ -34,7 +36,12 @@ var createBufferWriteStream =
return true;
};

var ended = false;
ret.end = function(buffer) {
if (ended) {
return; // make sure callback is called only once
}
ended = true;
if (buffer) {
ret.write(buffer);
}
Expand All @@ -54,9 +61,9 @@ var createBufferWriteStream =
return true;
};
ret.destroy = ret.destroySoon = function() { ret.writeable = false; };
//Ignore. We don't send any events (like 'drain') to the stream.
ret.on = function (event, func) {};
ret.emit = function () {};
ret.removeListener = function () {};
ret.addListener('pipe', function(stream) {
stream.on('data', ret.write);
stream.on('end', ret.end);
});
return ret;
};
3 changes: 2 additions & 1 deletion lib/cli/iaas/upload/pageBlob.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ var uploadPageBlobFromBlobService =
// check footer (if vhd)
if (dynVHD) {
if (!compare(vhdInfo.footer.buffer, result.data)) {
exitWithError('Files are different - cannot upload incrementally. Use -f option to overwrite.');
exitWithError((result.data && result.data.length > 0 ? '' : 'Couldn\'t read cloud blob footer. ') +
'Files are different - cannot upload incrementally. Use -f option to overwrite.');
}
}
onBlobCreated();
Expand Down
43 changes: 11 additions & 32 deletions lib/cli/iaas/upload/vhdTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var fs = require('fs');
var path = require('path');
var util = require('util');
var streamMerger = require('./streamMerger');
var events = require('events');

//// VHD format constants
var SECTOR_SIZE = exports.SECTOR_SIZE = 512; // VHD sector size
Expand Down Expand Up @@ -167,8 +168,9 @@ var getVHDInfo =
var buf0 = new Buffer(bufferSize);
buf0.fill();

// possible TODO: inherit stream from events.EventEmitter similarly to streamMerger
var stream = {readable: true, _pos : start, _on: {}};
var stream = new events.EventEmitter();
stream.readable = true;
stream._pos = start;

function nyi() {
throw new Error('Not Yet Implemented');
Expand All @@ -180,7 +182,7 @@ var getVHDInfo =

process.nextTick(function() {
if (!createNextStream(block0, startPosWithinBlock0)) {
onEvent('end'); // make sure we emit 'end' event if VHD has no data at all
stream.emit('end'); // make sure we emit 'end' event if VHD has no data at all
}
});

Expand Down Expand Up @@ -259,23 +261,23 @@ var getVHDInfo =

stream._fileStream.on('error', function onError(error) {
stream.readable = false;
onEvent('error', error);
stream.emit('error', error);
});

stream._fileStream.on('end', function onEnd() {
stream._fileStream = null;
if (!stream.readable || createNextStream(block + 1)) {
return;
}
onEvent('end');
stream.emit('end');
});

stream._fileStream.on('data', function onData(data) {
if (!stream.readable || !data.length) {
return;
}
fillToPos(fixedStart);
onEvent('data', data);
stream.emit('data', data);
stream._pos += data.length;
});

Expand All @@ -295,43 +297,20 @@ var getVHDInfo =
});
}
};

stream.on = function(event, func) {
if (!stream._on[event]) {
stream._on[event] = [func];
} else {
stream._on[event].push(func);
}
};
stream.addListener = stream.on;
stream.once = nyi;
stream.removeListener = nyi;
stream.removeAllListeners = nyi;
stream.setMaxListeners = function() {};
stream.listeners = function(event) {
return stream._on[event];
};

function onEvent(event, param) {
var onEventList = stream._on[event];
for (var i in onEventList) {
onEventList[i](param);
}
}


function fillToPos(newPos) { // ignores any newPos parameters before current position

if (newPos > footer.currentSize && newPos > stream._pos) {
fillToPos(footer.currentSize);
onEvent('data', footer.buffer.slice(
stream.emit('data', footer.buffer.slice(
stream._pos - footer.currentSize,
newPos - footer.currentSize));
return;
}

while (newPos > stream._pos) {
var count = Math.min(newPos - stream._pos, buf0.length);
onEvent('data', count === buf0.length ? buf0 : buf0.slice(0, count));
stream.emit('data', count === buf0.length ? buf0 : buf0.slice(0, count));
stream._pos += count;
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "azure",
"author": "Microsoft Corporation",
"version": "0.6.2",
"version": "0.6.4",
"description": "Windows Azure Client Library for node and Command Line Tool",
"tags" : ["azure", "sdk"],
"keywords": [ "node", "azure" ],
Expand Down

0 comments on commit d4d3ca0

Please sign in to comment.