-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ipfs files write
offset command appears faulty
#2380
Comments
I am also confused by truncate, which appears to only work with |
Can you illustrate with your expectations? Seems from your example that create is working fine. Were you expecting for there to be an 'offset' on the first hello world? On the second example it looks it performed well (started writing 4 bytes from the left, note: offset is not number of chars, but number of bytes) |
re: truncate imagine a file being an array: [a,b,c,d,e,f] and each position is a character encoded in just one byte (like ASCII)
|
This may have been what threw me. I did not expect that. I expected the first 'hello world' (second command) to be offset, too. |
See it like a computer 💻👀
says that it has 1) create a file if it doesn't exist; 2) move the writing pointer to byte 2; 3) write the incoming bytes, in this case it is a string 'hello world'
PS: on 3), someone might have thought that is a total valid operation and implementing a FS that does just that |
the truncate flag truncates the file before writing. the offset flag, if specified past the bounds of a file, will sparsely expand the file to the given offset, and begin the write from there. |
although, it does seem strange that you ended up with 'hehello world' instead of 'hellhello world' ill take a look at that |
@whyrusleeping That's because it uses bytes instead of characters, which to me seems wrong. Or, at least, we should document that. @diasdavid Got it. Thanks for the explanation. I think this can be closed when we document that it is bytes and not chars. |
@diasdavid: are we not using UTF-8? Why wouldn't two english chars like "he" be two bytes? |
The only documentation in |
Succinct: "Truncate the rest of the file from the offset, before appending input." |
In utf8, 'he' is in fact two bytes. utf8 uses varints |
I think using bytes for the offset and not characters is sensible as characters would be dependent on interpreting the input character set and all bets will then be off if you're trying to write bytes into a binary file. FWIW the
|
Yes. This appears to work as intended. Closing as this is an old issue. |
I'm not sure I am doing this right, but I am having issues making the offset command work. It does not seem to work simultaneously with
create
, and any subsequent usage doesn't seem to follow the offset I specify.What I've run, so far:
The text was updated successfully, but these errors were encountered: