image

  • フォト Amazonギフト券
    ※この時計の時刻は、閲覧しているパソコンのものであり、必ずしも正確な時間とは限りません

検索

最近のトラックバック

無料ブログはココログ

« enchant.js を追加: express + coffeescript + mongoose の練習 (その2) | トップページ | socket.io の examples/chat/app.js も coffeescript にしてみた。 »

2011-12-25

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 にしてみた。 »

コメント

この記事へのコメントは終了しました。

トラックバック


この記事へのトラックバック一覧です: coffeescript で unzip:

« enchant.js を追加: express + coffeescript + mongoose の練習 (その2) | トップページ | socket.io の examples/chat/app.js も coffeescript にしてみた。 »

mokuji

2013年12月
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

google

  • twitter
  • __
  • _
    Googleボットチェッカー

合わせて読む

  • 合わせて読む
    フィードメーター - katoy: cocolog あわせて読みたい

リンク