delete data from end of file over 2 G

How might I remove the last 5 bytes from the data fork of a binary file that is larger than 2 gigabytes in Mac OS X 10.2 or 10.3? Preserving the resource fork is not necessary. Thanks.

There are several shell utilities that can do this, but in the interest of supporting AppleScript, the following should work using the standard file handling commands:

property twogig : 2 ^ 31 – number of bytes in 2GB
set theFile to open for access file “path:to:file” with write permission
if (get EOF theFile) > twogig then
set EOF theFile to twogig
end if
close access theFile

The idea here is that get EOF returns the size of the file. If it’s larger than 2GB simply set the EOF to 2GB. Anything past that point in the file is lost.

Thanks. This was helpful. Here’s the final source for the applet that does what I want when I drag the desired file onto its icon.

on open sourcefile
display dialog “Are you sure you want to remove the last 5 bytes of this file?”
set the_target to sourcefile
set theFile to open for access file (the_target as string) with write permission
set full_file_length to get eof theFile
set desired_file_length to (full_file_length - 5)
set eof theFile to desired_file_length
close access theFile
end open