Fail to read and write file using xbmcvfs.File in Frodo - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32) +--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26) +--- Thread: Fail to read and write file using xbmcvfs.File in Frodo (/showthread.php?tid=145013) |
Fail to read and write file using xbmcvfs.File in Frodo - Popeye - 2012-11-12 Hi, EDIT: I have runned into more issues and have updated the post. I try to use the new xbmcvfs.File api for reading and writing to files. PHP Code: fd_a = xbmcvfs.File(file_a) However I end up getting the error for buffer "TypeError: argument 1 must be string without null bytes, not str" The problem is that the file I try to read us full of null bytes... PHP Code: for line in buffer: So what should I do? RE: Fail to read and write file using xbmcvfs.File in Frodo - Popeye - 2012-11-14 No one have any clue? Who was the developer adding the API? RE: Fail to read and write file using xbmcvfs.File in Frodo - jmarshall - 2012-11-14 There's a ticket on trac that may be associated with this: http://trac.xbmc.org/ticket/13545 Cheers, Jonathan RE: Fail to read and write file using xbmcvfs.File in Frodo - Popeye - 2012-11-14 Thanks for your answer! The ticket is about the the xbmcvfs.write() appends \x00 to the buffer being written. In my case the buffer cannot contain \x00. If I do: PHP Code: fd_a = xbmcvfs.File(file_a) The local_file_b gets written without any issues.. RE: Fail to read and write file using xbmcvfs.File in Frodo - jfcarroll - 2012-11-14 We're thinking through ways to resolve this. It will probably result in a change to the current API. It will probably use a bytebuffer in python on both the read and write sides. Plus, MAYBE a string and length on both the read and write sides. How does that work? RE: Fail to read and write file using xbmcvfs.File in Frodo - Nuka1195 - 2012-11-14 Not sure I understand by byte buffer. For string and length. Are you saying. Text="this is some text" f.write(text, len(text)) This would work I guess, but can't you strip the \x00 character? Isn't that the terminator for char? RE: Fail to read and write file using xbmcvfs.File in Frodo - Popeye - 2012-11-14 I'm not sure I understand either. Do you have a mock up code example? All I want is to read and write in a similar fashion as when working with local files (e.g. open(file, 'w')). On top of this I lack the tell() method . RE: Fail to read and write file using xbmcvfs.File in Frodo - jfcarroll - 2012-11-14 Sorry, given that I primarily deal in java, I said 'bytebuffer' but meant 'bytearray.' The length written would be the exact length of the byte array provided. RE: Fail to read and write file using xbmcvfs.File in Frodo - Popeye - 2012-11-15 Ok, will you post here once you have merged your code? I have a early addon release not working once your change is done... RE: Fail to read and write file using xbmcvfs.File in Frodo - Nuka1195 - 2012-11-15 the read seems to work fine for me as is, meaning there does not have to be a \x00 at the end of the file. PHP Code: text = unicode(xbmcvfs.File(lyrics_path, "r").read().strip(BOM_UTF8), "UTF-8") as for the write. PHP Code: return file->Write( (void*) pBuffer, strlen( pBuffer ) + 1 ) > 0; i'm testing removing the +1, is that needed for binary writes? RE: Fail to read and write file using xbmcvfs.File in Frodo - Nuka1195 - 2012-11-15 I can't see where: PHP Code: return file->Write( (void*) pBuffer, strlen( pBuffer ) ) > 0; wouldn't work. it seems to work fine. I did not test binary too well, i just wrote the same text as "wb", so not sure if that is a good test. I do notice open for append doesn't seem supported. Is that something that can be added? PHP Code: if (mode && strncmp(mode, "w", 1) == 0) by the above i guess binary writes aren't supported anyways. RE: Fail to read and write file using xbmcvfs.File in Frodo - Popeye - 2012-11-15 I see I was a bit unclear. For writing the buffer cannot contain \x00 and it also appends \x00 at the end of a written file. RE: Fail to read and write file using xbmcvfs.File in Frodo - Nuka1195 - 2012-11-15 the change above corrects the appending of \x00, but if it's a terminating character, then yes your text to write can not include it. RE: Fail to read and write file using xbmcvfs.File in Frodo - Popeye - 2012-11-15 I don't fully follow you , all I want is to read and write binary data and not text (e.g. read and write the first 1000 bytes of a big file) RE: Fail to read and write file using xbmcvfs.File in Frodo - Nuka1195 - 2012-11-15 binary reads and writes don't appear to be supported. my issue was \x00 being appended. PHP Code: else if (mode && strncmp(mode, "a", 1) == 0) bOverWrite appears to be ignored, so "a" append does not work" |