The Artima Developer Community
Sponsored Link

Python Answers Forum
read function and different file types

2 replies on 1 page. Most recent reply: Sep 4, 2004 3:30 AM by Alex Ozhigov

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Alex Ozhigov

Posts: 2
Nickname: neutrino4
Registered: Sep, 2004

read function and different file types Posted: Sep 2, 2004 12:44 PM
Reply to this message Reply
Advertisement
I'm writing a program for file transfering like ftp and i'm currently debugging it in Windows. The main piece of code is a simple while loop with read/write and send/recv calls and the cycle ends when the buffer we read is null. This code works perfectly when transfering a plain text files with only ASCII symbols in it. But if i try sending a non-text file (like zip archive or exe) it doesn't read the whole file but only a small piece of it is read and then it finds the EOF (null buffer is returned). So i read the manual and it says that some systems distinguish text files and binary ones, and in order to read binary data on such systems 'b' option should be presented in at file creation like f=file(file_name,'rb'). And i set this mode and now the size of non-text files received is allways greater then the size of the source ones. And when i try for example to open an archive it says 'unexpected end of archive'. So how to read binary files?


Andy

Posts: 28
Nickname: adn
Registered: Jul, 2004

Re: read function and different file types Posted: Sep 3, 2004 6:22 AM
Reply to this message Reply
Sounds like the file modes are alright. Are you using the socket module? You need to make sure all the data is sent by checking the return value of .send(data) on your socket (how much was sent).

Otherwise post relevant sections of your code for us to look at.

Alex Ozhigov

Posts: 2
Nickname: neutrino4
Registered: Sep, 2004

Re: read function and different file types Posted: Sep 4, 2004 3:30 AM
Reply to this message Reply
Oops... i forgot to add 'b' to the file mode when creating a file on the receiving side... I feel such a fool...

Flat View: This topic has 2 replies on 1 page
Topic: just a simple loop question Previous Topic   Next Topic Topic: Getting started with python...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use