Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update documentation, cleanup debris.

  • Loading branch information...
commit 805f7501f5d89756d97272f2a3660bd0669ea59b 1 parent 88d3ec8
Reid Burke reid authored

Showing 1 changed file with 18 additions and 27 deletions. Show diff stats Hide diff stats

  1. +18 27 lib/onyx.js
45 lib/onyx.js
@@ -18,19 +18,18 @@ var fs = require("fs");
18 18 var path = require("path");
19 19 var util = require("util");
20 20 var assert = require("assert");
21   -var EventEmitter = require("events").EventEmitter;
22 21 var mime = require("./mime");
23 22
24 23 /**
25 24 * Onyx streams a collection of files
26 25 * as a response to an HTTP request.
  26 + *
  27 + * @class Onyx
  28 + * @constructor
27 29 */
28   -
29 30 function Onyx () {
30 31 }
31 32
32   -util.inherits(Onyx, EventEmitter);
33   -
34 33 var proto = Onyx.prototype;
35 34
36 35 /**
@@ -49,6 +48,16 @@ proto.makeArray = function (obj) {
49 48 return arr;
50 49 }
51 50
  51 +/**
  52 + * Implementation of a fs.stat collector for
  53 + * multiple files.
  54 + *
  55 + * @method statCollector
  56 + * @protected
  57 + * @param {Array} files An array of fille-qualified filenames.
  58 + * @param {Object} source A map of filenames to their `fs.stat` results.
  59 + * @param {Function} cb Callback, 2-arity: error or null, the map of stat results.
  60 + */
52 61 proto.statCollector = function statCollector (files, source, cb) {
53 62 var file = files.shift();
54 63 var onyx = this;
@@ -83,10 +92,13 @@ proto.statCollector = function statCollector (files, source, cb) {
83 92 * Aggregate fs#stat across multiple files.
84 93 *
85 94 * The callback recieves an object with:
  95 + *
86 96 * - size: total size of all files
87 97 * - mtime: latest mtime
88 98 * - files: individual stat objects per-file
  99 + *
89 100 * @method mstat
  101 + * @private
90 102 * @param {Array} files
91 103 * @param {Function} cb Callback
92 104 */
@@ -122,20 +134,8 @@ function xfer (res, files, cb) {
122 134 * a HTTP response, stream them to the HTTP response
123 135 * and callback when complete.
124 136 *
125   - * While streaming the response, carbon-copy the
126   - * file data to the baton's `cache` MochaCache
127   - * instance. If a file exists in that cache,
128   - * serve it from there instead of going to
129   - * the filesystem.
130   - *
131   - * **When a cache object is specified, this
132   - * implementation assumes files being served
133   - * will not change during the server's operation.**
134   - * If a file changes on disk and it's still in the
135   - * cache, problems can occur if it falls out of the
136   - * file cache before the "FS mstat" cache, since the
137   - * streamed file may not match its length.
138   - *
  137 + * @method stream
  138 + * @protected
139 139 * @param {Object} baton The baton, containing files, res, and stat.
140 140 * @param {Function} cb Callback, 1-arity, the error or null.
141 141 */
@@ -223,15 +223,10 @@ proto.handle = function (status, baton, cb) {
223 223 res.write(baton.prepend);
224 224 }
225 225
226   - // TODO register metrics start
227   - // var beforeStream = +new Date();
228   - onyx.emit("streamStart");
229 226 onyx.stream(baton, function (err) {
230 227 if (!err && baton.postpend) {
231 228 res.write(baton.postpend);
232 229 }
233   - // TODO register metrics end
234   - onyx.emit("streamEnd");
235 230 cb(err);
236 231 });
237 232 }
@@ -243,10 +238,6 @@ proto.handle = function (status, baton, cb) {
243 238 * in the same request in the order they appear in the file
244 239 * array.
245 240 *
246   - * **This implementation assumes files being served
247   - * will not change during the server's operation.**
248   - * See the stream function above for more details.
249   - *
250 241 * The HTTP request is **not** ended by this function. Call
251 242 * res.end directly in your callback after checking for an
252 243 * 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.