Permalink
Browse files

use random string instead of timestamp for unique filenames. account …

…for windows more, closes #7.
  • Loading branch information...
1 parent ae8d52f commit 7a7e63459abad6cc1b7ea99bea6f780d312932c2 @chjj committed Jan 30, 2012
Showing with 11 additions and 5 deletions.
  1. +11 −5 lib/multipart.js
View
@@ -8,7 +8,8 @@ var fs = require('fs')
, path = require('path')
, EventEmitter = require('events').EventEmitter
, StringDecoder = require('string_decoder').StringDecoder
- , set = require('./qs').set;
+ , set = require('./qs').set
+ , each = Array.prototype.forEach;
/**
* Character Constants
@@ -44,7 +45,7 @@ var Parser = function(type, options) {
this.key = new Buffer('\r\n--' + key);
this._key = {};
- Array.prototype.forEach.call(this.key, function(ch) {
+ each.call(this.key, function(ch) {
this._key[ch] = true;
}, this);
@@ -364,7 +365,9 @@ Parser.prototype._finish = function() {
* Uploads
*/
-Parser.root = '/tmp';
+Parser.root = process.platform === 'win32'
+ ? 'C:/Temp'
+ : '/tmp';
/**
* Middleware
@@ -448,9 +451,12 @@ var isWindows = process.platform === 'win32';
var stream = function(name, dir) {
var ext = path.extname(name) || ''
, name = path.basename(name, ext) || ''
- , dir = dir || Parser.root;
+ , dir = dir || Parser.root
+ , tag;
- name = name.substring(0, 200) + '.' + Date.now();
+ tag = Math.random().toString(36).substring(2);
+
+ name = name.substring(0, 200) + '.' + tag;
name = path.join(dir, name) + ext.substring(0, 6);
name = name.replace(/\0/g, '');

0 comments on commit 7a7e634

Please sign in to comment.