Skip to content
Myr

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

7 files+25 added−32 removed

modified:lib/express/plugins/view.js+3 added-3 removed
modified:lib/express/spec/mocks.js+2 added-2 removed
43 unmodified lines
44 /**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 lines
modified:lib/express/core.js+8 added-8 removed
13 unmodified lines
14 */1516var 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// --- Route2223Route = Class({
193 unmodified lines
217 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 lines
251 })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 lines
modified:lib/express/http.js+2 added-2 removed
modified:lib/express/request.js+3 added-3 removed
189 unmodified lines
190 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 type
74 unmodified lines
modified:lib/express/static.js+5 added-3 removed
12// Express - Static - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34var path = require('path'),5 posix = require('posix')5 fs = require('fs')6 7// --- InvalidPathError89InvalidPathError = ExpressError.extend({
38 unmodified lines
48 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 lines
modified:spec/node.js+2 added-11 removed
2 unmodified lines
3require("jspec")4require("express")5require("express/spec")67quit = process.exit7print = puts8quit = process.exit9readFile = require('fs').readFileSync1010readFile = 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}1911function run(specs) {12 specs.forEach(function(spec){13 JSpec.exec('spec/spec.' + spec + '.js')14 })
46 unmodified lines