From a874a6dd0ae87f565a053324fed12bbc9a6152ce Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Sun, 25 Jan 2009 15:09:23 -0500 Subject: Fixed bugs with opening binary files; core/file_io.lua --- core/file_io.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'core/file_io.lua') diff --git a/core/file_io.lua b/core/file_io.lua index d9f1c25e..3adb9d89 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -28,7 +28,11 @@ local function open_helper(filename) local buffer = textadept.new_buffer() local f, err = io.open(filename) if f then - buffer:set_text(f:read('*all')) + local text = f:read('*all') + local chunk = #text > 65536 and text:sub(1, 65536) or text + if chunk:find('\0') then buffer.code_page = 0 end -- binary file; no UTF-8 + buffer:add_text(text, #text) + buffer:goto_pos(0) buffer:empty_undo_buffer() f:close() end -- cgit v1.2.3