'use strict';

// Imports
var fs = require('fs');
var url = require('url');

// Helper throws if the 'file:' protocol is not being used
function ensureFileProtocol(uri) {
  var parsedUri = url.parse(uri);
  if (parsedUri.protocol !== 'file:') {
    throw new Error('URI does not use the \'file:\' protocol: ' + uri);
  }
  return parsedUri;
}

// Returns an object that looks like http.IncomingMessage
function responseFor(uri) {
  return {
    headers: {},
    request: {
      href: uri
    },
    statusCode: 200
  };
}

/**
 * Returns a readable stream for the specified file in a similar manner to the
 * request package.
 *
 * @param {string} uri URI for the file using the 'file:' protocol.
 * @returns {Stream} Readable stream for the file's content.
 */
function requestFile(uri) {
  var parsedUri = ensureFileProtocol(uri);
  var stream = fs.createReadStream(parsedUri.pathname);
  // Make stream look like http.ClientRequest
  stream.abort = function unused() {};
  stream.on('readable', function onReadable() {
    stream.emit('response', responseFor(uri));
    stream.emit('end');
  });
  return stream;
}

/**
 * Invokes callback with a response and body for the specified file in a
 * similar manner to the request package.
 *
 * @param {string} uri URI for the file using the 'file:' protocol.
 * @param {function} callback Callback taking (error, response, body).
 * @returns {void}
 */
requestFile.get = function requestFileGet(uri, callback) {
  var parsedUri = ensureFileProtocol(uri);
  // Read file and invoke callback
  fs.readFile(parsedUri.pathname, { encoding: 'utf8' }, function onRead(err, body) {
    callback(err, responseFor(uri), body);
  });
};

// Export a request-like API (subset)
module.exports = requestFile;

@@ -959,14 +959,15 @@
 ion 
-unused
+onAbort
 () %7B
@@ -1066,16 +1066,20 @@
 ri));%0A  
+%7D);%0A
   stream
@@ -1083,20 +1083,58 @@
 eam.
-emit('end');
+on('data', function onData() %7B%0A    // Flowing mode
 %0A  %7D

Fix handling of stream to work cross-platform.