[Pythonmac-SIG] Best Way to Copy Resource Fork Data?

Jack Jansen jack@oratrix.nl
Fri, 14 Jan 2000 11:17:50 +0100


> file1 = ('Macintosh HD:TEST.EPS')
> file2 = ('Macintosh HD:TEST2.EPS')
> x = MacOS.openrf(file2, 'w')
> y = MacOS.openrf(file1, 'w')
> 
> input = y.read(1000000)   # <----  This is the problem part!
> x.write(input)

Well, you're mixing up your x'es, y's and open everything with "w" mode...
The following should work:
  x = MacOS.openrf(file1, "rb")
  y = MacOS.openrf(file2, "wb")
  while 1:
    data = x.read(100000)
    if not data: break
    y.write(data)

The rb/wb aren't strictly needed, r/w is ok, but this is clearer from a 
documentation point of view. Resource forks don't support reads without 
argument (too difficult to implement), hence the loop.

And you might also want to look in the macostools module, if you're trying to 
copy both forks of a file there's a routine in there that already does this, 
and it also copies the relevant parts of the finder info, etc.
--
Jack Jansen             | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++
www.oratrix.nl/~jack    | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm