Skip to content
Browse files

Update documentation, cleanup debris.

  • Loading branch information...
1 parent 88d3ec8 commit 805f7501f5d89756d97272f2a3660bd0669ea59b @reid committed
Showing with 18 additions and 27 deletions.
  1. +18 −27 lib/onyx.js
View
45 lib/onyx.js
@@ -18,19 +18,18 @@ var fs = require("fs");
var path = require("path");
var util = require("util");
var assert = require("assert");
-var EventEmitter = require("events").EventEmitter;
var mime = require("./mime");
/**
* Onyx streams a collection of files
* as a response to an HTTP request.
+ *
+ * @class Onyx
+ * @constructor
*/
-
function Onyx () {
}
-util.inherits(Onyx, EventEmitter);
-
var proto = Onyx.prototype;
/**
@@ -49,6 +48,16 @@ proto.makeArray = function (obj) {
return arr;
}
+/**
+ * Implementation of a fs.stat collector for
+ * multiple files.
+ *
+ * @method statCollector
+ * @protected
+ * @param {Array} files An array of fille-qualified filenames.
+ * @param {Object} source A map of filenames to their `fs.stat` results.
+ * @param {Function} cb Callback, 2-arity: error or null, the map of stat results.
+ */
proto.statCollector = function statCollector (files, source, cb) {
var file = files.shift();
var onyx = this;
@@ -83,10 +92,13 @@ proto.statCollector = function statCollector (files, source, cb) {
* Aggregate fs#stat across multiple files.
*
* The callback recieves an object with:
+ *
* - size: total size of all files
* - mtime: latest mtime
* - files: individual stat objects per-file
+ *
* @method mstat
+ * @private
* @param {Array} files
* @param {Function} cb Callback
*/
@@ -122,20 +134,8 @@ function xfer (res, files, cb) {
* a HTTP response, stream them to the HTTP response
* and callback when complete.
*
- * While streaming the response, carbon-copy the
- * file data to the baton's `cache` MochaCache
- * instance. If a file exists in that cache,
- * serve it from there instead of going to
- * the filesystem.
- *
- * **When a cache object is specified, this
- * implementation assumes files being served
- * will not change during the server's operation.**
- * If a file changes on disk and it's still in the
- * cache, problems can occur if it falls out of the
- * file cache before the "FS mstat" cache, since the
- * streamed file may not match its length.
- *
+ * @method stream
+ * @protected
* @param {Object} baton The baton, containing files, res, and stat.
* @param {Function} cb Callback, 1-arity, the error or null.
*/
@@ -223,15 +223,10 @@ proto.handle = function (status, baton, cb) {
res.write(baton.prepend);
}
- // TODO register metrics start
- // var beforeStream = +new Date();
- onyx.emit("streamStart");
onyx.stream(baton, function (err) {
if (!err && baton.postpend) {
res.write(baton.postpend);
}
- // TODO register metrics end
- onyx.emit("streamEnd");
cb(err);
});
}
@@ -243,10 +238,6 @@ proto.handle = function (status, baton, cb) {
* in the same request in the order they appear in the file
* array.
*
- * **This implementation assumes files being served
- * will not change during the server's operation.**
- * See the stream function above for more details.
- *
* The HTTP request is **not** ended by this function. Call
* res.end directly in your callback after checking for an
* error. That's because in the event of a stream error,

0 comments on commit 805f750

Please sign in to comment.
Something went wrong with that request. Please try again.