Skip to content

Instantly share code, notes, and snippets.

@saibotsivad
Created December 19, 2012 06:35
Show Gist options
  • Save saibotsivad/4334849 to your computer and use it in GitHub Desktop.
Save saibotsivad/4334849 to your computer and use it in GitHub Desktop.
Thinking through some export/import details.
var zip = new require('node-zip')()
us.map(blog.posts, function(post) {
if (post.is_attachment) {
console.log("Downloading: " + post.attachment_url)
request(post.attachment_url, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log("Saving " + post.folder + post.fileName)
zip.file(post.folder + post.fileName, body)
}
})
} else {
// create the string that goes into the file
// create the metadata text string
var content = ""
us.map(us.keys(post), function(key){
if (key !== 'content' && key !== 'folder' && key !== 'fileName') {
content = content + key + ": " + post[key] + "\n"
}
})
// using the text-metadata-parser requires an extra \n between the metadata and the content
content = content + "\n"
// content string
content = content + post.content
zip.file(post.folder + post.fileName, content)
}
})
// output file
var data = zip.generate({base64:false,compression:'DEFLATE'})
fs.writeFile('output.zip', data, 'binary')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment