swapBytes

Reverses byte-pairs in a file. Eg, a file containing “ab” will contain “ba”, and a file containing “abcd” will contain “badc”.

OS version: OS X

(*
swapBytes
Reverses byte-pairs in a file. Eg, a file containing "ab" will contain "ba", and a file containing "abcd" will contain "badc".
This handler is not intended to handle great amounts of data. 5 MB is fine. 50 MB is not fine. If you need such capability, you can easilly modify this handler.

Parameters:
f: file path, alias, posix path to a file

Example:
swapBytes("path:to:file.txt")
*)

to swapBytes(f)
	set f to f as Unicode text
	if f does not contain ":" then set f to POSIX file f as Unicode text
	
	set f to alias f
	
	if (f as text) ends with ":" then error "No folders!"
	
	do shell script "dd conv=swab < " & quoted form of POSIX path of f & " > /tmp/jfileLib_swapBytes"
	try
		set f to (open for access f with write permission)
		write (read ("/tmp/jfileLib_swapBytes" as POSIX file)) to f starting at 0
		close access f
	on error msg number n
		try
			close access f
		end try
		error msg number n
	end try
end swapBytes

property |version| : 1.0
property |from| : "jfileLib"
property author : "Pescados Software · PescadosWeb.com"
property |date| : date "sábado, 24 julio 2004 00:00:00"
property license : "freeware, open-source"