file.read() doesn't read the whole file
R. David Murray
rdmurray at bitdance.com
Mon Mar 23 14:50:16 CET 2009
Sreejith K <sreejithemk at gmail.com> wrote:
> > Try and write an example that shows the problem in fifteen lines or
> > less. Much easier for us to focus on the issue that way.
> import os
> def read(length, offset):
> snap = open('mango.txt_snaps/snap1/0','r')
> data = snap.read(length)
> print data
> This code shows what actually happens inside the code I've written.
> This prints the 4096 bytes from the file '0' which is only 654 bytes.
> When we run the code we get the whole file. That's right. I also get
> it. But when this read() function becomes the file class read()
> function in fuse, the data printed is not the whole but only a few
> lines from the beginning. I usually use less to read a file, when
> 'less'ing a file (whose size is less than 4096bytes) a call to read
> (0,4096) is made and data is returned. 'less' use this data returned
> by my fuse read() function to display its contents. But it was
> supposed to be the whole lines in the file like the example, but its
> not.... This is the problem I'm facing. Did I do something wrong here ?
If I'm understanding you correctly, you are saying that when you use
this function as the fuse read function you don't get the whole file,
and you are verifying this by using 'less' to read the 'file' exposed
by fuse. Correct?
So you still have not decoupled the python read from the fuse read in
your debugging. You are focused on the fact that the python read "must
be failing", yet you still (as far as you have told us) not _proven_
that by logging the value returned from the read. Until you do that,
you can't even be sure where your problem is.
If you have done it, show us the logging output, please.
R. David Murray http://www.bitdance.com
More information about the Python-list