Created
January 11, 2012 15:35
-
-
Save dmachi/1595210 to your computer and use it in GitHub Desktop.
tbz2 serializer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Media({ | |
mediaType: "application/x-bzip-compressed-tar", | |
getQuality: function(object){ | |
if (object && object.manifest && object.manifest.length>0){ | |
return 1; | |
} | |
return 0; | |
}, | |
serialize: function(object, parameters, request){ | |
//console.log("Serialize object to tbz: ", object, parameters, request); | |
var zip = spawn('tar', ['cjLf', '-', object.path]); | |
var f = LazyArray({ | |
"transfer-encoding": "chunked", | |
'content-disposition': "attachment; filename=Collection_" + object.id+ ".tbz2", | |
"content-type": "application/x-bzip-compressed-tar", | |
some: function(callback){ | |
var def = new defer(); | |
zip.stdout.on('data',callback); | |
zip.on('exit', function (code) { | |
def.resolve(true); | |
}); | |
return def; | |
} | |
}); | |
f.forEach.binary=true; | |
return f; | |
}, | |
deserialize: function(inputStream){ | |
console.log('tbz2 deserialize not implemented yet'); | |
/* | |
return when(forEachableToString(inputStream), function(body){ | |
if(body.charAt(0) == "{" || body.charAt(0) == "["){ | |
print("A content type of text/plain was specified, but the content appears to be JSON, and will be parsed as JSON"); | |
return JSONExt.parse(body); | |
} | |
return body; | |
}); | |
*/ | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment