Re: read from file
Re: read from file
- Subject: Re: read from file
- From: Andy Wylie <email@hidden>
- Date: Mon, 05 Aug 2002 20:00:13 +1200
on 5/8/02 2:54 PM +1200: email@hidden wrote:
>
Everything works fine until I try to load a large file into a variable.
>
Then I get an "out of memory" error.
>
this is an FAQ so please excuse this old example of reading chunks...
on open theFile
set |eof| to get eof of file theFile
open for access alias theFile
try
set startChunk to 1
set endChunk to 0
repeat until endChunk = |eof|
set endChunk to startChunk + 4024
if endChunk > |eof| then set endChunk to |eof|
set theText to read theFile from startChunk to endChunk
if (offset of "CalGray" in theText) > 0 then
display dialog "CalGray @ offset " & startChunk + (offset of
"CalGray" in theText)
exit repeat
end if
if startChunk > 1 then
set startChunk to endChunk - 10
else
set startChunk to endChunk
end if
end repeat
close access theFile
on error m number n
error {n, m}
close access theFile
end try
end open
_____________________________ Andy
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.