Skip to content

Instantly share code, notes, and snippets.

@uchcode
Created July 16, 2017 00:38
Show Gist options
  • Select an option

  • Save uchcode/555b1152f4dc78991617547da378a6e0 to your computer and use it in GitHub Desktop.

Select an option

Save uchcode/555b1152f4dc78991617547da378a6e0 to your computer and use it in GitHub Desktop.
巨大なUTF8テキストファイルを一行ずつ読み込む ref: http://qiita.com/tom-u/items/fdfb8e4b38e2aefdb442
app_readline = Library('FileHandle').readline
app = Application.currentApplication()
app.includeStandardAdditions = true
p = '/Users/uchcode/Desktop/巨大テキスト.txt'
try {
let f = app.openForAccess(p)
while(1) {
let t = app_readline(f)
// ここで取得した1行のテキストを処理する
console.log(t)
}
} catch(e) {
// console.log( Automation.getDisplayString(e) )
// -39 eofを超えた
if (e.errorNumber != -39) throw e
} finally {
try { app.closeAccess(p) } catch(e) {
// console.log( Automation.getDisplayString(e) )
// -38 pは開かれていない
if (e.errorNumber != -38) throw e
}
}
on readline(theFile)
return read theFile before "\n" as «class utf8»
--return read theFile before return as «class utf8»
end readline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment