Created
July 16, 2017 00:38
-
-
Save uchcode/555b1152f4dc78991617547da378a6e0 to your computer and use it in GitHub Desktop.
巨大なUTF8テキストファイルを一行ずつ読み込む ref: http://qiita.com/tom-u/items/fdfb8e4b38e2aefdb442
This file contains hidden or 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
| 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 | |
| } | |
| } |
This file contains hidden or 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
| 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