Parse multipart response from AWS S3

This commit is contained in:
Matt Colyer 2013-10-04 09:24:19 -07:00
parent d39797fdca
commit 15a62eab63
2 changed files with 13 additions and 4 deletions

View File

@ -117,6 +117,7 @@
},
"devDependencies": {
"biscotto": "0.0.17",
"formidable": "~1.0.14",
"fstream": "0.1.24",
"grunt": "~0.4.1",
"grunt-cli": "~0.1.9",

View File

@ -2,6 +2,7 @@ fs = require 'fs'
path = require 'path'
request = require 'request'
formidable = require 'formidable'
module.exports = (grunt) ->
{spawn, mkdir, rm, cp} = require('./task-helpers')(grunt)
@ -107,10 +108,17 @@ module.exports = (grunt) ->
cacheDirectory = getCachePath(version)
rm(cacheDirectory)
mkdir(cacheDirectory)
cacheFile = path.join(cacheDirectory, 'atom-shell.zip')
outputStream = fs.createWriteStream(cacheFile)
outputStream.on 'close', -> callback(null, cacheFile)
inputStream.pipe(outputStream)
form = new formidable.IncomingForm()
form.uploadDir = cacheDirectory
form.maxFieldsSize = 100 * 1024 * 1024
form.on 'file', (name, file) ->
cacheFile = path.join(cacheDirectory, 'atom-shell.zip')
fs.renameSync(file.path, cacheFile)
callback(null, cacheFile)
form.parse response, (error) ->
if error
grunt.log.error("atom-shell #{version.cyan} failed to download")
else
if response.statusCode is 404
grunt.log.error("atom-shell #{version.cyan} not found")