Started converting fs module
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 347c884 · Browse files · 7 files·+25 added−32 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+25 added−32 removed
- tests:+4 added−13 removed
- other:+21 added−19 removed
Provenance
- Commit
f03e460- Tree
014a4e5- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
347c884
7 files changed+25 added−32 removed
modified:lib/express/plugins/view.js+3 added-3 removed
3 unmodified lines456789891011121371 unmodified lines858687888989909192936 unmodified lines3 unmodified lines/** * Module dependencies. */
var posix = require('posix'), utils = require('express/utils')var utils = require('express/utils'), fs = require('fs')
/** * Supported template engines. */71 unmodified lines } if (set('cache view contents') && self.cache.get(path)) render(self.cache.get(path)) else posix.cat(path).addCallback(function(content){ fs.readFile(path, function(content){ set('cache view contents') ? render(self.cache.set(path, content)) : render(content) })6 unmodified linesmodified:lib/express/spec/mocks.js+2 added-2 removed
43 unmodified lines44 /**45 * Store _code_ and _headers_.46 */47 48- sendHeader: function(code, headers) {48+ writeHeader: function(code, headers) {49 this.status = code50 this.headers = headers51 },52 53 /**54 * Store _body_.55 */56 57- sendBody: function(body) {57+ write: function(body) {58 this.body = body59 },60 61 /**68 unmodified linesmodified:lib/express/core.js+8 added-8 removed
13 unmodified lines14 */15 16 var multipart = require('multipart'),17 events = require('events'),18- File = require('file').File,19- utils = require('express/utils')18+ utils = require('express/utils'),19+ fs = require('fs')20 21 // --- Route22 23 Route = Class({193 unmodified lines217 request.params = { post: {}}218 promise.timeout(set('upload timeout') || 5000)219 stream.addListener('part', function(part){220 if (part.filename) {221- var file = new File(part.tempfile = '/tmp/express-' + Number(new Date) + utils.uid(), 'w', { encoding: 'binary' })222- ++pendingFiles221 part.pos = 0222+ ++pendingFiles223+ part.tempfile = '/tmp/express-' + Number(new Date) + utils.uid()224 part.addListener('body', function(chunk){225- file.write(chunk, part.pos, 'binary').addErrback(function(){225+ fs.write(chunk, part.pos, 'binary').addErrback(function(){226 promise.emitError.apply(promise, arguments)227 })228 part.pos += chunk.length229 })230 .addListener('complete', function(){231- file.close().addCallback(function(){231+ fs.close().addCallback(function(){232 if (!--pendingFiles)233 promise.emitSuccess()234 }).addErrback(function(){235 promise.emitError.apply(promise, arguments)15 unmodified lines251 })252 }253 else254 request255- .addListener('body', function(chunk){ request.body += chunk })256- .addListener('complete', function(){ self.route(request, response) })255+ .addListener('data', function(chunk){ request.body += chunk })256+ .addListener('end', function(){ self.route(request, response) })257 })258 .listen(this.port, this.host, this.backlog)259 puts('Express started at http://' + this.host + ':' + this.port + '/ in ' + Express.environment + ' mode')260 },63 unmodified linesmodified:lib/express/http.js+2 added-2 removed
36 unmodified lines37383940414241424344454633 unmodified lines36 unmodified lines headers['content-length'] = data.length headers['content-type'] = 'application/x-www-form-urlencoded' } var request = client.request(method, path + search + hash, headers) if (data) request.sendBody(data) request.finish(function(response){ if (data) request.write(data) request.close(function(response){ if (response.statusCode < 200 || response.statusCode >= 400) promise.emitError(new Error('request failed with status ' + response.statusCode + ' "' + http.STATUS_CODES[response.statusCode] + '"')) else if (response.statusCode >= 300 && response.statusCode < 400) request(method, response.headers.location, headers, data, promise)33 unmodified linesmodified:lib/express/request.js+3 added-3 removed
189 unmodified lines190 this.response.body = body191 this.trigger('response')192 if (typeof this.response.body != 'string') throw new InvalidResponseBody(this)193 if (typeof this.response.status != 'number') throw new InvalidStatusCode(this.response.status)194- this.response.sendHeader(this.response.status, this.response.headers)195- this.response.sendBody(this.response.body, encoding)196- this.response.finish()194+ this.response.writeHeader(this.response.status, this.response.headers)195+ this.response.write(this.response.body, encoding)196+ this.response.close()197 },198 199 /**200 * Set Content-Type header to the mime type74 unmodified linesmodified:lib/express/static.js+5 added-3 removed
1 2 // Express - Static - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4 var path = require('path'),5- posix = require('posix')5+ fs = require('fs')6 7 // --- InvalidPathError8 9 InvalidPathError = ExpressError.extend({38 unmodified lines48 return request.contentType(cache.type),49 request.halt(200, cache.content, 'binary')50 path.exists(file, function(exists){51 if (!exists) return request.halt()52- posix.stat(file).addCallback(function(stats){52+ fs.stat(file, function(e, stats){53+ if (e) throw e54 if (!stats.isFile()) return request.halt()54- posix.cat(file, 'binary').addCallback(function(content){55+ fs.readFile(file, 'binary', function(e, content){56+ if (e) throw e57 request.contentType(file)58 if (set('cache static files'))59 request.cache.set(file, { type: file, content: content })60 request.halt(200, content, 'binary')5 unmodified linesmodified:spec/node.js+2 added-11 removed
2 unmodified lines3 require("jspec")4 require("express")5 require("express/spec")6 7-quit = process.exit7 print = puts8+quit = process.exit9+readFile = require('fs').readFileSync10 10-readFile = function(path) {11- var result12- require('posix')13- .cat(path, "utf8")14- .addCallback(function(contents){ result = contents })15- .addErrback(function(){ throw new Error("failed to read file `" + path + "'") })16- .wait()17- return result18-}19-11 function run(specs) {12 specs.forEach(function(spec){13 JSpec.exec('spec/spec.' + spec + '.js')14 })46 unmodified lines