In general, on most systems, the only modifications you can make without
a temporary file or something comparable are those which do not change the
number of characters in a file. You can't insert or delete characters in
the middle of a file.
-s
···
On 2010-01-16, Milo Luo <lxybhbh@gmail.com> wrote:
I meant without string or tmp file, write to original file.
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net | Seebs.Net <-- lawsuits, religion, and funny pictures Fair game (Scientology) - Wikipedia <-- get educated!
I often wondered if there is any OS floating around out there that goes
beyond the traditional file semantics (replace, append, truncate, extend).
For example:
-- prepend
-- delete (from beginning or middle)
-- insert
I would think that many of those operations would be painfully inefficient
unless perhaps they were done on block-sized chunks to avoid having to
keep track of partially used blocks.
Gary Wright
···
On Jan 16, 2010, at 12:50 PM, Seebs wrote:
On 2010-01-16, Milo Luo <lxybhbh@gmail.com> wrote:
I meant without string or tmp file, write to original file.
In general, on most systems, the only modifications you can make without
a temporary file or something comparable are those which do not change the
number of characters in a file. You can't insert or delete characters in
the middle of a file.
But yes, that's the point, and that's why XML (or JSON, or Yaml) is not
efficient as a database format, unless you work around it somehow. It's fine
(preferred, even) if the files are small enough, but yes, you are going to
have to write to a tempfile first, then move that on top of the original file.
Or, if you're feeling reckless, you can truncate the original file to 0, then
overwrite it directly.
···
On Saturday 16 January 2010 11:50:04 am Seebs wrote:
On 2010-01-16, Milo Luo <lxybhbh@gmail.com> wrote:
> I meant without string or tmp file, write to original file.
In general, on most systems, the only modifications you can make without
a temporary file or something comparable are those which do not change the
number of characters in a file. You can't insert or delete characters in
the middle of a file.
I meant without string or tmp file, write to original file.
In general, on most systems, the only modifications you can make without
a temporary file or something comparable are those which do not change
the
number of characters in a file. You can't insert or delete characters
in
the middle of a file.
-s
Hi, Seebs
Do you mean it's related with the file system API?
If it can located or got the node & text from XML, it should be modified
the node or text value without too many problems.
I don't know if I misunderstand the process of getting the node & text.
Anyway, thanks.
BR,
Milo
···
On 2010-01-16, Milo Luo <lxybhbh@gmail.com> wrote:
Do you mean it's related with the file system API?
Yes.
If it can located or got the node & text from XML, it should be modified
the node or text value without too many problems.
Not in general.
The problem is that, unless the new value is the same length as the old
value, modifying text in the middle of the file produces problems.
Imagine that we have a really simple XML file:
<greet>hello, world</greet>
You want to change that to "hello, world!". So you do. And you get:
<greet>hello, world!/greet>
See the problem? You can't make the later parts of the file move ahead;
you would actually have to rewrite the whole file.
-s
···
On 2010-01-17, Milo Luo <lxybhbh@gmail.com> wrote:
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net | Seebs.Net <-- lawsuits, religion, and funny pictures Fair game (Scientology) - Wikipedia <-- get educated!
> I meant without string or tmp file, write to original file.
In general, on most systems, the only modifications you can make without
a temporary file or something comparable are those which do not change the
number of characters in a file. You can't insert or delete characters in
the middle of a file.
Not true; you can append to the end of a file.
But yes, that's the point, and that's why XML (or JSON, or Yaml) is not
efficient as a database format, unless you work around it somehow. It's
fine
(preferred, even) if the files are small enough, but yes, you are going
to
have to write to a tempfile first, then move that on top of the original
file.
Or, if you're feeling reckless, you can truncate the original file to 0,
then
overwrite it directly.
Hi, David
It seems that I can only truncate the original file to 0, then overwrite
it directly, but it will cost a lot of IO if the file is very large.
But seems that it's the best way to do that.
Thank you,sir.
BR,
Milo
···
On Saturday 16 January 2010 11:50:04 am Seebs wrote:
On 2010-01-16, Milo Luo <lxybhbh@gmail.com> wrote: