plain text file to UTF-8 file

Convert a plain text file to a utf-8 file (and back).
The “textfile2utf8” writes optionally the three-byte BOM header of utf-8 files.

OS version: OS X

--> SAMPLE USAGE

--> convert plain text file to utf-8 with BOM header
textfile2utf8(choose file, true)

--> convert utf-8 file to plain text (mac-ascii)
utf8file2text(choose file with prompt "Choose a utf-8 encoded file...")


to textfile2utf8(f, header)
	set oldContents to (read f)
	set f to (open for access f with write permission)
	set eof of f to 0
	if header then write (ASCII character 239) & (ASCII character 187) & (ASCII character 191) to f
	write oldContents to f as «class utf8» starting at eof
	close access f
end textfile2utf8
to utf8file2text(f)
	set oldContents to (read f as «class utf8»)
	set f to (open for access f with write permission)
	set eof of f to 0
	write oldContents to f as string
	close access f
end utf8file2text

property |version| : 1.0
property author : "Pescados Software · [url=http://www.pescadosweb.com/"]http://www.pescadosweb.com/"[/url]
property |date| : date "domingo, 21 marzo 2004 17:46:58"
property license : "freeware, open-source"