A Method to get bytes of file without loading file?

  • Thread starter Thread starter Hillbilly
  • Start date Start date
H

Hillbilly

I haven't used File.Length yet so I don't know but I have to write some
validation that requires learning how many bytes are in a file. Is there
some way to query a file without loading the file into memory?

And if I learn there's a way to do this with Javascript I just might pee my
pants I'll be so happy :-)
 
Looks like files have to be loaded into memory to get the length in bytes.
The context is "this sucks" when lots of huge video file sizes have to be
determined using a web app.

Any idea how Windows Explorer reports the size on disk with a simple hover
event?
 
Hillbilly said:
Looks like files have to be loaded into memory to get the length in
bytes. [...]

Why do you say that? It's certainly not true that you have to load a
file into memory, _any_ of the file never mind all of it. So, what has
given you the impression that you do?
 
Looks like files have to be loaded into memory to get the length in bytes.

"Looks like"? Why? Because you tried it? Everything you've said so far
suggests you have not tried ANYTHING, even though it would only take a
couple of minutes to do so. Now I can understand not wanting to try it and
preferring to just get someone to answer your question instead, but even
when you're given the answer YOU DON'T BELIEVE IT! So what exactly do you
want? I mean, it's almost leaning towards trolling at this point.
 
Looks like files have to be loaded into memory to get the length in
bytes. The context is "this sucks" when lots of huge video file sizes
have to be determined using a web app.

Any idea how Windows Explorer reports the size on disk with a simple
hover event?

FileInfo.Length and Windows Explorer does it the same way: by reading
the files meta info.

They do not do by reading all the content. In fact it would be
impossible to do it by reading the content, because without getting
the length from file meta info, then there would be no way to
know where the file ended in the last allocation unit on disk.

You should ask that in a JavaScript or at least a web group.

But since JavaScript can not access the file system on the
server or the file system on the client, then ...

Arne
 
Peter Duniho said:
Hillbilly said:
Looks like files have to be loaded into memory to get the length in
bytes. [...]

Why do you say that? It's certainly not true that you have to load a file
into memory, _any_ of the file never mind all of it. So, what has given
you the impression that you do?

I said that because the documentation does not clearly state one way or
another the property of a file on disk is expressed as metadata which can be
read without loading the file into memory.
 
Jeff Johnson said:
"Looks like"? Why? Because you tried it? Everything you've said so far
suggests you have not tried ANYTHING, even though it would only take a
couple of minutes to do so. Now I can understand not wanting to try it and
preferring to just get someone to answer your question instead, but even
when you're given the answer YOU DON'T BELIEVE IT! So what exactly do you
want? I mean, it's almost leaning towards trolling at this point.

I said that because the documentation does not clearly state one way or
another the property of a file on disk is expressed as metadata which can be
read without loading the file into memory.
 
Arne Vajhøj said:
FileInfo.Length and Windows Explorer does it the same way: by reading
the files meta info.

They do not do by reading all the content. In fact it would be
impossible to do it by reading the content, because without getting
the length from file meta info, then there would be no way to
know where the file ended in the last allocation unit on disk.


You should ask that in a JavaScript or at least a web group.

But since JavaScript can not access the file system on the
server or the file system on the client, then ...

Arne

Apparently, SL4 running OOB which is being called SLOOB will support
querying a file on the local file system to obtain that metadata and then
return the value to the page generated on the server. I am looking forward
to learning that and how its done.

Meanwhile, thank you, I have a file property validation dilemma and its
helpful to hear confirmed that I can learn to use the FileInfo.Length
property without loading a file into memory.
 
Patrice said:
FileInfo gives *information* about the file and doesn't need to load the
whole file in memory to gets it size.

That said, as you talked about doing this using javascript I suspect that
you are trying to read the size of client size files from your web app
which is not possible out of the box.
If needed you can wait the benefit you'll get from this info against
installing a client side java, activex or silvelrlight or god knows what
applet. Else you'll now the size only when the file is posted.

If those files are stored on your server, you have no problem. What have
you tried that doesn't work ?

As said previously explaining a bit more what you are trying to do could
help to raise better answers...

I have file property validation dilemma I haven't had to learn anything
about until now so thanks for your insight Patrice. The files aren't on the
server and not accessible to the page that needs the size of that file in
bytes where it is on the file system of wherever it happens to be.

The XML MediaRSS protocol requires this data for enclosures; video and other
types of files transported using RSS.
 
Peter Duniho said:
Hillbilly said:
Looks like files have to be loaded into memory to get the length in
bytes. [...]

Why do you say that? It's certainly not true that you have to load a
file into memory, _any_ of the file never mind all of it. So, what has
given you the impression that you do?

I said that because the documentation does not clearly state one way or
another the property of a file on disk is expressed as metadata which
can be read without loading the file into memory.

It is not explicit about it. And in general it is not wise to make
assumptions about implementation.

But as I explained in my reply, then there has to be meta data -
otherwise reading would not get the correct number of bytes.

Arne
 
Apparently, SL4 running OOB which is being called SLOOB will support
querying a file on the local file system to obtain that metadata and
then return the value to the page generated on the server. I am looking
forward to learning that and how its done.

Out of browser means that the restrictions may not have to apply.

Arne
 
Yea, thanks, but for the future please note in the English language
assumption and a presumption have different meanings. I --presumed-- and did
not --assume-- which is why I asked about what I presumed based on the
circumstances whereas when one assumes the person goes forth to take their
time acting upon what they assumed or were misled to believe in which case
learning after all the time that was spent the assumption was wrong.

As good as it is, Microsoft's documentation is still notoriously good for
shit in this regard which is why I and so many others have recently been
asked how to improve MSDN.

Hence, it always pays to ask ahead of time before acting on something you
know you must act upon because asking ahead of time can often help prevent a
waste of time.

Arne Vajhøj said:
Peter Duniho said:
Hillbilly wrote:
Looks like files have to be loaded into memory to get the length in
bytes. [...]

Why do you say that? It's certainly not true that you have to load a
file into memory, _any_ of the file never mind all of it. So, what has
given you the impression that you do?

I said that because the documentation does not clearly state one way or
another the property of a file on disk is expressed as metadata which
can be read without loading the file into memory.

It is not explicit about it. And in general it is not wise to make
assumptions about implementation.

But as I explained in my reply, then there has to be meta data -
otherwise reading would not get the correct number of bytes.

Arne
 
Arne Vajhøj said:
Hillbilly wrote:
Looks like files have to be loaded into memory to get the length in
bytes. [...]

Why do you say that? It's certainly not true that you have to load a
file into memory, _any_ of the file never mind all of it. So, what has
given you the impression that you do?

I said that because the documentation does not clearly state one way or
another the property of a file on disk is expressed as metadata which
can be read without loading the file into memory.

It is not explicit about it. And in general it is not wise to make
assumptions about implementation.

But as I explained in my reply, then there has to be meta data -
otherwise reading would not get the correct number of bytes.
Yea, thanks, but for the future please note in the English language
assumption and a presumption have different meanings. I --presumed-- and
did not --assume-- which is why I asked about what I presumed based on
the circumstances whereas when one assumes the person goes forth to take
their time acting upon what they assumed or were misled to believe in
which case learning after all the time that was spent the assumption was
wrong.

Hm.

I think I told you that you could make an assumption.
As good as it is, Microsoft's documentation is still notoriously good
for shit in this regard which is why I and so many others have recently
been asked how to improve MSDN.

If you want to ask whether you can assume Length not to read
the entire file using the words "Looks like files have to be loaded into
memory to get the length in bytes.", then I don't think I would
ask you to do that.

Arne
 
Back
Top