coffeescript で unzip
js2coffee で https://github.com/springmeyer/node-zipfile/blob/master/bin/unzip.js を coffeescript にしてみた。
(変換結果に対して ヘルプのメッセージ変更、空行の追加をしてある。)
$ coffee unzip.coffee ~/work/Books/What_Is_Node/What_Is_Node_.epub
unzipping: META-INF/container.xml
unzipping: OEBPS/cover.html
unzipping: OEBPS/index.html
unzipping: OEBPS/ch01.html
unzipping: OEBPS/ch01s08.html
unzipping: OEBPS/LiberationSerif.otf
unzipping: OEBPS/ch01s02.html
unzipping: OEBPS/LiberationMono-Italic.otf
unzipping: OEBPS/ch01s04.html
unzipping: OEBPS/LiberationMono-BoldItalic.otf
unzipping: OEBPS/author_bios.html
unzipping: OEBPS/ch01s05.html
unzipping: OEBPS/oreilly_large.gif
unzipping: OEBPS/content.opf
unzipping: OEBPS/httpatomoreillycomsourceoreillyimages867093.png.jpg
unzipping: OEBPS/ch01s03.html
unzipping: OEBPS/LiberationMono-Bold.otf
unzipping: OEBPS/httpatomoreillycomsourceoreillyimages867095.png.jpg
unzipping: OEBPS/core.css
unzipping: OEBPS/httpatomoreillycomsourceoreillyimages867097.png.jpg
unzipping: OEBPS/httpatomoreillycomsourceoreillyimages867099.png.jpg
unzipping: OEBPS/httpatomoreillycomsourceoreillyimages867091.jpg
unzipping: OEBPS/toc.ncx
unzipping: OEBPS/ch01s09.html
unzipping: OEBPS/LiberationMono.otf
unzipping: OEBPS/ch01s07.html
unzipping: OEBPS/ch01s06.html
この epub ファイルは
http://www.amazon.com/What-Is-Node-ebook/dp/B005ISQ7JC/
の無料の電子書籍。
$ cat unzip.coffee
zip = require("zipfile")
fs = require("fs")
path = require("path")
usage = "usage: coffeescript unzip.coffee <zipfile>"
file = process.argv[2]
unless file
console.log usage
process.exit 1
zf = new zip.ZipFile(file)
zf.names.forEach (name) ->
uncompressed = path.join(".", name)
dirname = path.dirname(uncompressed)
fs.mkdir dirname, 0755, (err) ->
throw err if err and not err.code.match(/^EEXIST/)
if path.extname(name)
buffer = zf.readFileSync(name)
fd = fs.openSync(uncompressed, "w")
console.log "unzipping: " + name
fs.writeSync fd, buffer, 0, buffer.length, null
fs.closeSync fd
« enchant.js を追加: express + coffeescript + mongoose の練習 (その2) | トップページ | socket.io の examples/chat/app.js も coffeescript にしてみた。 »
この記事へのコメントは終了しました。
« enchant.js を追加: express + coffeescript + mongoose の練習 (その2) | トップページ | socket.io の examples/chat/app.js も coffeescript にしてみた。 »
コメント