-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serve injected YUI library using sendfiles.
- Loading branch information
Showing
4 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(function attachEventsToYUITest () { | ||
|
||
if (!window.YUITest) return window.setTimeout(attachEventsToYUITest, 15); | ||
|
||
var Runner = window.YUITest.TestRunner; | ||
|
||
Runner.on(Runner.COMPLETE_EVENT, function (data) { | ||
if (!window.YUITest.CLI) return; | ||
|
||
YUI().use("test", function (Y) { | ||
var reporter = new Y.Test.Reporter(window.YUITest.CLI.url); | ||
reporter.report(data); | ||
}); | ||
}); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var fs = require("fs"); | ||
|
||
// never-caching multi-file version of sendfile | ||
exports.sendfiles = function (files, appendString, callback) { | ||
var self = this; | ||
var contentLength = 0; | ||
var filesRead = 0; | ||
var contentStore = []; | ||
var io = new (require("events").EventEmitter); | ||
|
||
if ( | ||
appendString && "string" !== typeof appendString | ||
) return Error.raise("TypeError", "appendString must be a string"); | ||
|
||
io.addListener("end", function (file) { | ||
if (appendString) { | ||
contentLength += appendString.length; | ||
contentStore.push(appendString); | ||
} | ||
contentLength += contentStore.length - 1; | ||
self.header('Content-Length', contentLength); | ||
// send the last file's content type. | ||
self.contentType(file); | ||
self.respond(200, contentStore.join("\n")); | ||
}); | ||
|
||
// the order of files is important | ||
for ( | ||
var idx = 0, len = files.length; idx < len; idx++ | ||
) (function (idx) { // closure on idx | ||
var file = files[idx]; | ||
fs.stat(file, function (err, stat) { | ||
if (err) | ||
return "errno" in err && err.errno === 2 | ||
? self.notFound() | ||
: self.error(err, callback) | ||
fs.readFile(file, function (err, content) { | ||
if (err) return self.error(err, callback) | ||
contentStore[idx] = content; | ||
contentLength += stat.size; | ||
if ( | ||
++filesRead == files.length | ||
) io.emit("end", file); | ||
}) | ||
}) | ||
})(idx); | ||
|
||
return this; | ||
} |