os.write() messed up?
#1
i am currently working on getting mythtv preview screenshots displaying in xbmc for the xbmc mythtv project. i have a .png file that i am copying from a smb share. when i test the code to copy a .png on a linux machine, the .png is copied correctly byte for byte. however, when i copy the .png using the interpreter in xbmc, the .png ends up being corrupted.

at first i suspected that the smb module that i am using was messed up so i put some print statements in to see how many bytes were written to the file by counting up the values returned by write(). it all added up to 34875 which is the correct size of the file. however, when i view the file on the xbox filesystem over an ftp connection, the size is 34993 and if i transfer it in binary mode back to linux and try to view it, gimp reports "png file corrupted by ascii conversion".

so i thought i should write a program to demonstrate this bug. unfortunately, the following code hangs in xbmc after writing 6 bytes. the same code running in linux makes an exact copy of the file.

Quote:import os, xbmcgui

try:
src = 'q:\\scripts\\1051_20040505143000_20040505145500.nuv.png'
dst = 'q:\\scripts\\preview.png'

s = os.stat( src )
ifd = os.open( src, os.o_rdonly )
ofd = os.open( dst, os.o_wronly | os.o_trunc | os.o_creat )

if ifd and ofd:
n = 0
while n < s[6]:
b = os.read( ifd, 128000 )
n += os.write( ofd, b )
os.close( ifd )
os.close( ofd )
except exception, ex:
xbmcgui.dialog().ok("exception", str(ex))

any ideas? i am running the april 27, 2004 build but i don't think it would make much of a difference since os.py in python23.zlib has not changed since july 2003...
Reply
#2
assuming the file that you sent back to linux is 34993 bytes, have you tried to do a byte comparison and see where the changes are occuring or what is being added?

edit: does read assume a string. if so it may be trying to escape some of the "ascii" characters? just an idea
Reply
#3
ok, i managed to figure out a way to get it work. using the python built-in file object, you can open a file for writing in binary mode and it gets written correctly.

i guess it was late last night when i tried using os.write() because i should've thought to check for file objects in python. although it is a bit odd given that os.write() is supposedly a lower level interface...
Reply

Logout Mark Read Team Forum Stats Members Help
os.write() messed up?0