Updated WGI_OUTPUT_STREAM.put_file_content .

This commit is contained in:
2016-10-25 13:44:44 +02:00
parent ac908e4efd
commit 5e79751522

View File

@@ -37,15 +37,17 @@ feature -- Output
end end
end end
put_file_content (a_file: FILE; a_offset: INTEGER; a_count: INTEGER) put_file_content (a_file: FILE; a_offset: INTEGER; a_byte_count: INTEGER)
-- Send `a_count' bytes from the content of file `a_file' starting at offset `a_offset'. -- Send `a_byte_count' bytes from the content of file `a_file' starting at offset `a_offset'.
--| Could be redefine for optimization. --| Could be redefined for optimization.
require require
a_file_closed_or_openread: a_file.exists and then (a_file.is_access_readable or a_file.is_closed)
is_open_write: is_open_write is_open_write: is_open_write
a_file_not_void: a_file /= Void a_file_not_void: a_file /= Void
local local
l_close_needed: BOOLEAN l_close_needed: BOOLEAN
n: INTEGER l_remain: INTEGER
l_done: BOOLEAN
s: STRING s: STRING
do do
if a_file.exists and then a_file.is_access_readable then if a_file.exists and then a_file.is_access_readable then
@@ -55,23 +57,25 @@ feature -- Output
l_close_needed := True l_close_needed := True
a_file.open_read a_file.open_read
end end
if a_offset > 0 then
a_file.move (a_offset)
end
from from
n := a_count l_remain := a_byte_count
if a_offset > 0 then l_done := False
a_file.move (a_offset)
end
until until
a_file.exhausted or n <= 0 a_file.exhausted or l_done
loop loop
a_file.read_stream (n.min (4_096)) a_file.read_stream (l_remain.min (4_096))
s := a_file.last_string s := a_file.last_string
if s.is_empty then if s.is_empty then
-- network error? -- network error?
n := 0 l_done := True
else else
n := n - s.count
check n >= 0 end
put_string (s) put_string (s)
l_remain := l_remain - s.count
check l_remain >= 0 end
l_done := l_remain = 0
end end
end end
if l_close_needed then if l_close_needed then