Skip to content
This repository
Browse code

[dist refactor] Update to use `mime` and `pkginfo` modules.

  • Loading branch information...
commit 061d9ac4bc8b2d088df14586864a182072a6a5cc 1 parent df24e8b
Charlie Robbins authored August 18, 2011
17  lib/cloudfiles.js
@@ -10,17 +10,20 @@ require.paths.unshift(__dirname);
10 10
 
11 11
 var cloudfiles = exports;
12 12
 
13  
-// Version
14  
-cloudfiles.version = [0, 2, 0];
  13
+//
  14
+// Load package information using `pkginfo`.
  15
+//
  16
+require('pkginfo')(module, 'version');
15 17
 
  18
+//
16 19
 // Resources
  20
+//
17 21
 cloudfiles.Config           = require('cloudfiles/config').Config;
  22
+cloudfiles.Cloudfiles       = require('cloudfiles/core').Cloudfiles;
18 23
 cloudfiles.Container        = require('cloudfiles/container').Container; 
19 24
 cloudfiles.StorageObject    = require('cloudfiles/storage-object').StorageObject;
20 25
 
  26
+//
21 27
 // Core methods
22  
-cloudfiles.createClient     = require('cloudfiles/core').createClient;
23  
-cloudfiles.Cloudfiles       = require('cloudfiles/core').Cloudfiles;
24  
-
25  
-// Mime types
26  
-cloudfiles.mime             = require('cloudfiles/mime').mime;
  28
+//
  29
+cloudfiles.createClient     = require('cloudfiles/core').createClient;
8  lib/cloudfiles/core.js
@@ -11,6 +11,7 @@ var http = require('http'),
11 11
     path = require('path'),
12 12
     url = require('url'),
13 13
     async = require('async'),
  14
+    mime = require('mime'),
14 15
     request = require('request'),
15 16
     cloudfiles = require('../cloudfiles'),
16 17
     config = require('./config'),
@@ -364,10 +365,13 @@ Cloudfiles.prototype.addFile = function (container, options, callback) {
364 365
     client: this,
365 366
     upload: lstream,
366 367
     uri: this.storageUrl(container, options.remote),
367  
-    contentType: cloudfiles.mime.type(options.remote),
368  
-    headers: options.headers
  368
+    headers: options.headers || {}
369 369
   };
370 370
   
  371
+  if (options.headers && !options.headers['content-type']) {
  372
+    options.headers['content-type'] = mime.lookup(options.remote);
  373
+  }
  374
+  
371 375
   return common.rackspace(addOptions, callback, function (body, res) {
372 376
     callback(null, true);
373 377
   });
207  lib/cloudfiles/mime.js
... ...
@@ -1,207 +0,0 @@
1  
-/*
2  
- * mime.js: Utility module for determining file mime-types
3  
- *
4  
- * (C) 2010 Nodejitsu Inc.
5  
- * MIT LICENSE
6  
- *
7  
- */
8  
-
9  
-var defaultMime = exports.defaultMime = 'text/plain';
10  
-
11  
-exports.mime = {
12  
-
13  
-  /**
14  
-   * Return mime type for the given path, 
15  
-   * otherwise default to exports.defaultMime 
16  
-   * ("application/octet-stream").
17  
-   *
18  
-   * @param {String} path
19  
-   * @return {String}
20  
-   * @api public
21  
-   */
22  
-
23  
-  type: function getMime(path) {
24  
-    var index = String(path).lastIndexOf(".");
25  
-    if (index < 0) {
26  
-      return defaultMime;
27  
-    }
28  
-    var type = exports.mime.types[path.substring(index).toLowerCase()] || defaultMime;
29  
-    return (/(text|javascript)/).test(type) ? type + "; charset=utf-8" : type;
30  
-  },
31  
-
32  
-  /**
33  
-   * Mime types.
34  
-   */
35  
-
36  
-  types: {
37  
-    ".3gp"   : "video/3gpp",
38  
-    ".a"     : "application/octet-stream",
39  
-    ".ai"    : "application/postscript",
40  
-    ".aif"   : "audio/x-aiff",
41  
-    ".aiff"  : "audio/x-aiff",
42  
-    ".asc"   : "application/pgp-signature",
43  
-    ".asf"   : "video/x-ms-asf",
44  
-    ".asm"   : "text/x-asm",
45  
-    ".asx"   : "video/x-ms-asf",
46  
-    ".atom"  : "application/atom+xml",
47  
-    ".au"    : "audio/basic",
48  
-    ".avi"   : "video/x-msvideo",
49  
-    ".bat"   : "application/x-msdownload",
50  
-    ".bin"   : "application/octet-stream",
51  
-    ".bmp"   : "image/bmp",
52  
-    ".bz2"   : "application/x-bzip2",
53  
-    ".c"     : "text/x-c",
54  
-    ".cab"   : "application/vnd.ms-cab-compressed",
55  
-    ".cc"    : "text/x-c",
56  
-    ".chm"   : "application/vnd.ms-htmlhelp",
57  
-    ".class" : "application/octet-stream",
58  
-    ".com"   : "application/x-msdownload",
59  
-    ".conf"  : "text/plain",
60  
-    ".cpp"   : "text/x-c",
61  
-    ".crt"   : "application/x-x509-ca-cert",
62  
-    ".css"   : "text/css",
63  
-    ".csv"   : "text/csv",
64  
-    ".cxx"   : "text/x-c",
65  
-    ".deb"   : "application/x-debian-package",
66  
-    ".der"   : "application/x-x509-ca-cert",
67  
-    ".diff"  : "text/x-diff",
68  
-    ".djv"   : "image/vnd.djvu",
69  
-    ".djvu"  : "image/vnd.djvu",
70  
-    ".dll"   : "application/x-msdownload",
71  
-    ".dmg"   : "application/octet-stream",
72  
-    ".doc"   : "application/msword",
73  
-    ".dot"   : "application/msword",
74  
-    ".dtd"   : "application/xml-dtd",
75  
-    ".dvi"   : "application/x-dvi",
76  
-    ".ear"   : "application/java-archive",
77  
-    ".eml"   : "message/rfc822",
78  
-    ".eot"   : "application/vnd.bw-fontobject",
79  
-    ".eps"   : "application/postscript",
80  
-    ".exe"   : "application/x-msdownload",
81  
-    ".f"     : "text/x-fortran",
82  
-    ".f77"   : "text/x-fortran",
83  
-    ".f90"   : "text/x-fortran",
84  
-    ".flv"   : "video/x-flv",
85  
-    ".for"   : "text/x-fortran",
86  
-    ".gem"   : "application/octet-stream",
87  
-    ".gemspec" : "text/x-script.ruby",
88  
-    ".gif"   : "image/gif",
89  
-    ".gz"    : "application/x-gzip",
90  
-    ".h"     : "text/x-c",
91  
-    ".hh"    : "text/x-c",
92  
-    ".htm"   : "text/html",
93  
-    ".html"  : "text/html",
94  
-    ".ico"   : "image/vnd.microsoft.icon",
95  
-    ".ics"   : "text/calendar",
96  
-    ".ifb"   : "text/calendar",
97  
-    ".iso"   : "application/octet-stream",
98  
-    ".jar"   : "application/java-archive",
99  
-    ".java"  : "text/x-java-source",
100  
-    ".jnlp"  : "application/x-java-jnlp-file",
101  
-    ".jpeg"  : "image/jpeg",
102  
-    ".jpg"   : "image/jpeg",
103  
-    ".js"    : "application/javascript",
104  
-    ".json"  : "application/json",
105  
-    ".log"   : "text/plain",
106  
-    ".m3u"   : "audio/x-mpegurl",
107  
-    ".m4v"   : "video/mp4",
108  
-    ".man"   : "text/troff",
109  
-    ".mathml" : "application/mathml+xml",
110  
-    ".mbox"  : "application/mbox",
111  
-    ".mdoc"  : "text/troff",
112  
-    ".me"    : "text/troff",
113  
-    ".mid"   : "audio/midi",
114  
-    ".midi"  : "audio/midi",
115  
-    ".mime"  : "message/rfc822",
116  
-    ".mml"   : "application/mathml+xml",
117  
-    ".mng"   : "video/x-mng",
118  
-    ".mov"   : "video/quicktime",
119  
-    ".mp3"   : "audio/mpeg",
120  
-    ".mp4"   : "video/mp4",
121  
-    ".mp4v"  : "video/mp4",
122  
-    ".mpeg"  : "video/mpeg",
123  
-    ".mpg"   : "video/mpeg",
124  
-    ".ms"    : "text/troff",
125  
-    ".msi"   : "application/x-msdownload",
126  
-    ".odp"   : "application/vnd.oasis.opendocument.presentation",
127  
-    ".ods"   : "application/vnd.oasis.opendocument.spreadsheet",
128  
-    ".odt"   : "application/vnd.oasis.opendocument.text",
129  
-    ".ogg"   : "application/ogg",
130  
-    ".p"     : "text/x-pascal",
131  
-    ".pas"   : "text/x-pascal",
132  
-    ".pbm"   : "image/x-portable-bitmap",
133  
-    ".pdf"   : "application/pdf",
134  
-    ".pem"   : "application/x-x509-ca-cert",
135  
-    ".pgm"   : "image/x-portable-graymap",
136  
-    ".pgp"   : "application/pgp-encrypted",
137  
-    ".pkg"   : "application/octet-stream",
138  
-    ".pl"    : "text/x-script.perl",
139  
-    ".pm"    : "text/x-script.perl-module",
140  
-    ".png"   : "image/png",
141  
-    ".pnm"   : "image/x-portable-anymap",
142  
-    ".ppm"   : "image/x-portable-pixmap",
143  
-    ".pps"   : "application/vnd.ms-powerpoint",
144  
-    ".ppt"   : "application/vnd.ms-powerpoint",
145  
-    ".ps"    : "application/postscript",
146  
-    ".psd"   : "image/vnd.adobe.photoshop",
147  
-    ".py"    : "text/x-script.python",
148  
-    ".qt"    : "video/quicktime",
149  
-    ".ra"    : "audio/x-pn-realaudio",
150  
-    ".rake"  : "text/x-script.ruby",
151  
-    ".ram"   : "audio/x-pn-realaudio",
152  
-    ".rar"   : "application/x-rar-compressed",
153  
-    ".rb"    : "text/x-script.ruby",
154  
-    ".rdf"   : "application/rdf+xml",
155  
-    ".roff"  : "text/troff",
156  
-    ".rpm"   : "application/x-redhat-package-manager",
157  
-    ".rss"   : "application/rss+xml",
158  
-    ".rtf"   : "application/rtf",
159  
-    ".ru"    : "text/x-script.ruby",
160  
-    ".s"     : "text/x-asm",
161  
-    ".sgm"   : "text/sgml",
162  
-    ".sgml"  : "text/sgml",
163  
-    ".sh"    : "application/x-sh",
164  
-    ".sig"   : "application/pgp-signature",
165  
-    ".snd"   : "audio/basic",
166  
-    ".so"    : "application/octet-stream",
167  
-    ".svg"   : "image/svg+xml",
168  
-    ".svgz"  : "image/svg+xml",
169  
-    ".swf"   : "application/x-shockwave-flash",
170  
-    ".t"     : "text/troff",
171  
-    ".tar"   : "application/x-tar",
172  
-    ".tbz"   : "application/x-bzip-compressed-tar",
173  
-    ".tci"   : "application/x-topcloud",
174  
-    ".tcl"   : "application/x-tcl",
175  
-    ".tex"   : "application/x-tex",
176  
-    ".texi"  : "application/x-texinfo",
177  
-    ".texinfo" : "application/x-texinfo",
178  
-    ".text"  : "text/plain",
179  
-    ".tif"   : "image/tiff",
180  
-    ".tiff"  : "image/tiff",
181  
-    ".torrent" : "application/x-bittorrent",
182  
-    ".tr"    : "text/troff",
183  
-    ".ttf"   : "application/x-font-ttf",
184  
-    ".txt"   : "text/plain",
185  
-    ".vcf"   : "text/x-vcard",
186  
-    ".vcs"   : "text/x-vcalendar",
187  
-    ".vrml"  : "model/vrml",
188  
-    ".war"   : "application/java-archive",
189  
-    ".wav"   : "audio/x-wav",
190  
-    ".wma"   : "audio/x-ms-wma",
191  
-    ".wmv"   : "video/x-ms-wmv",
192  
-    ".wmx"   : "video/x-ms-wmx",
193  
-    ".woff"  : "font/woff",
194  
-    ".wrl"   : "model/vrml",
195  
-    ".wsdl"  : "application/wsdl+xml",
196  
-    ".xbm"   : "image/x-xbitmap",
197  
-    ".xhtml"   : "application/xhtml+xml",
198  
-    ".xls"   : "application/vnd.ms-excel",
199  
-    ".xml"   : "application/xml",
200  
-    ".xpm"   : "image/x-xpixmap",
201  
-    ".xsl"   : "application/xml",
202  
-    ".xslt"  : "application/xslt+xml",
203  
-    ".yaml"  : "text/yaml",
204  
-    ".yml"   : "text/yaml",
205  
-    ".zip"   : "application/zip"
206  
-  }
207  
-};
3  package.json
@@ -13,7 +13,8 @@
13 13
   "keywords": ["cloud computing", "api", "rackspace cloud", "cloudfiles"],
14 14
   "dependencies": {
15 15
     "async": "0.1.x",
16  
-    "mkdir": "0.0.x",
  16
+    "mime": "1.2.x",
  17
+    "pkginfo": "0.2.x",
17 18
     "request": "2.0.x"
18 19
   },
19 20
   "devDependencies": {
41  test/mime-test.js
... ...
@@ -1,41 +0,0 @@
1  
-/*
2  
- * mime-test.js: Tests for mime type indentification
3  
- *
4  
- * (C) 2010 Nodejitsu Inc.
5  
- * MIT LICENSE
6  
- *
7  
- */
8  
- 
9  
-var path = require('path'),
10  
-    vows = require('vows'),
11  
-    fs = require('fs'),
12  
-    assert = require('assert');
13  
-    
14  
-require.paths.unshift(path.join(__dirname, '..', 'lib'));
15  
-
16  
-var cloudfiles = require('cloudfiles');
17  
-
18  
-var tests = {};
19  
-
20  
-// Create a test for each mime type
21  
-Object.keys(cloudfiles.mime.types).forEach(function (ext) {
22  
-  var mimeType = cloudfiles.mime.types[ext],
23  
-      test = 'when passed a ' + ext + ' file',
24  
-      assertion = "should response with " + mimeType + " mimetype";
25  
-  
26  
-  tests[test] = { };
27  
-  tests[test][assertion] = function () {
28  
-    var testType = cloudfiles.mime.type('someFile' + ext);
29  
-    assert.isTrue(testType.indexOf(mimeType) !== -1);
30  
-  };
31  
-});
32  
-
33  
-// Create a batch for the specified mime type
34  
-var batch = {
35  
-  "When using the node-cloudfiles client": {
36  
-    "the mime type module": tests
37  
-  }
38  
-};
39  
-
40  
-// Export the batch with vows
41  
-vows.describe('cloudfiles/mime').addBatch(batch).export(module);

0 notes on commit 061d9ac

Please sign in to comment.
Something went wrong with that request. Please try again.