Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use new q-io library

  • Loading branch information...
commit 8eb491f41bb0078497b1c3887e2e1cec1a7c78ff 1 parent 3d55aa5
@SLaks SLaks authored
View
6 lib/FileResponse.js
@@ -29,7 +29,7 @@
var Response = require('./Response').Response;
var pathUtils = require('path');
var fs = require('fs');
-var qfs = require('q-fs');
+var qfs = require('q-io/fs');
var Q = require('q');
var util = require('util');
@@ -82,8 +82,8 @@ var FileResponse = Response.extend(
return qfs.stat(path).then(
function(stats) {
if (stats.isFile()) {
- r.setHeader('Content-Length', stats.size);
- r.enableCaching(stats.mtime);
+ r.setHeader('Content-Length', stats.size());
+ r.enableCaching(stats.lastModified());
return r;
}
else {
View
2  lib/ViewRegistry.js
@@ -29,7 +29,7 @@
var Class = require('capsela-util').Class
var Logger = require('capsela-util').Logger;
var Log = require('capsela-util').Log;
-var fs = require('q-fs');
+var fs = require('q-io/fs');
var Q = require('q');
var pathUtils = require('path');
View
2  lib/stages/Dispatcher.js
@@ -32,7 +32,7 @@
var Log = require('capsela-util').Log;
var capsela = require('../../');
-var fs = require('q-fs');
+var fs = require('q-io/fs');
var Q = require('q');
var Dispatcher = capsela.Stage.extend({
View
2  lib/stages/FileServer.js
@@ -29,7 +29,7 @@
var pathUtils = require('path');
var capsela = require('../../');
var Stage = capsela.Stage;
-var qfs = require('q-fs');
+var qfs = require('q-io/fs');
var Q = require('q');
var FileServer = Stage.extend({
View
2  package.json
@@ -15,7 +15,7 @@
"dependencies": {
"capsela-util": ">=0.1.0",
"q": "~0.8",
- "q-fs": ">=0.1.19",
+ "q-io": "~1.0.0",
"formidable": ">=1.0.5",
"jsdom": ">=0.2.0"
},
View
42 testing/tests/FileResponseTest.js
@@ -30,12 +30,23 @@ var testbench = require(__dirname + '/../TestBench');
var MonkeyPatcher = require('capsela-util').MonkeyPatcher;
var Pipe = require('capsela-util').Pipe;
var fs = require('fs');
-var qfs = require('q-fs');
+var qfs = require('q-io/fs');
var mp = new MonkeyPatcher();
var Q = require('q');
var FileResponse = require('../../').FileResponse;
+var fileStats = new qfs.Stats({
+ size: 527,
+ mtime: new Date(72000),
+ isFile: function() { return true; }
+});
+var dirStats = new qfs.Stats({
+ size: 527,
+ mtime: new Date(72000),
+ isFile: function() { return false; }
+});
+
module.exports["basics"] = {
tearDown: function(cb) {
@@ -45,17 +56,10 @@ module.exports["basics"] = {
"test create non-file": function(test) {
- var stats = {
- size: 527,
- mtime: new Date(72000),
- isFile: function() {
- return false;
- }
- };
mp.patch(qfs, 'stat', function(path) {
test.equal(path, '/images/sunrise.jpg');
- return Q.resolve(stats);
+ return Q.resolve(dirStats);
});
FileResponse.create('/images/sunrise.jpg').then(null,
@@ -68,17 +72,9 @@ module.exports["basics"] = {
"test create success": function(test) {
- var stats = {
- size: 527,
- mtime: new Date(72000),
- isFile: function() {
- return true;
- }
- };
-
mp.patch(qfs, 'stat', function(path) {
test.equal(path, '/images/sunrise.jpg');
- return Q.resolve(stats);
+ return Q.resolve(fileStats);
});
FileResponse.create('/images/sunrise.jpg').then(
@@ -97,17 +93,9 @@ module.exports["basics"] = {
var pipe = new Pipe();
var bodyBuffer = new Pipe(true);
- var stats = {
- size: 527,
- mtime: new Date(72000),
- isFile: function() {
- return true;
- }
- };
-
mp.patch(qfs, 'stat', function(path) {
test.equal(path, '/images/sunrise.jpg');
- return Q.resolve(stats);
+ return Q.resolve(fileStats);
});
mp.patch(fs, 'createReadStream', function(path) {
Please sign in to comment.
Something went wrong with that request. Please try again.