Skip to content

Commit

Permalink
Merge branch 'uid'
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Feb 1, 2010
2 parents 6490f0c + 29fe71c commit 50d1423
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/express/core.js
Expand Up @@ -223,7 +223,7 @@ Server = Class({
request.params = { post: {}}
stream.addListener('part', function(part){
if (part.filename) {
var file = new File(part.tempfile = '/tmp/express-' + Number(new Date), 'w')
var file = new File(part.tempfile = '/tmp/express-' + Number(new Date) + uid(), 'w')
part.pos = 0
part.addListener('body', function(chunk){
file.write(chunk, part.pos, 'binary')
Expand Down
14 changes: 14 additions & 0 deletions lib/express/helpers.js
Expand Up @@ -8,6 +8,20 @@
JSON.encode = JSON.stringify
JSON.decode = JSON.parse

/**
* Return a unique identifier.
*
* @return {string}
* @api public
*/

exports.uid = function() {
var uid = ''
for (var n = 4; n; --n)
uid += (Math.abs((Math.random() * 0xFFFFFFF) | 0)).toString(16)
return uid
}

/**
* Return the directory name of the given _path_.
*
Expand Down
7 changes: 7 additions & 0 deletions spec/spec.helpers.js
Expand Up @@ -21,6 +21,13 @@ describe 'Express'
end
end

describe 'uid()'
it 'should return a string of random characters'
uid().should.not.eql uid()
uid().length.should.be_greater_than 20
end
end

describe 'extname()'
it 'should return the a files extension'
extname('image.png').should.eql 'png'
Expand Down

0 comments on commit 50d1423

Please sign in to comment.