Comments (5)
And also the function getOffset()
confused me a bit, because in the documentation/help guide it says :
Returns: The current file pointer offset.
However in dataread.ts
line 298 on the description part it says:
Returns the current lastOffset
This two has different meaning and confused me 😅
I was using it for reading all the data up to the EndOfFile (which I later discovered option to pass in undefined which is not included in the documentation) through the equation (FileSize
- getOffset()
- 1) and didn't work since it is reading more data than available. Although in some cases we can get the "current" offset (or the next lastoffset
) by (lastoffset
+ lastsize
), while using readRowWithDetails
the lastsize
will be unknown/or variable in each block. Maybe consider changing the terms used or the code?
Anyways this is a very useful extension, I love it!
from binary-file-viewer.
Hi,
- When reading negative values the current offset is subtracted by the (abs) size, moving it backwards.
Then reading the next time this would be offset+size. I.e. it is at the same position as before. As it moves forward.
You just once move the offset back, afterwards everything is the same as if you would have used a positive size.
I.e. doing read(-1) multiple times always reads the same value. This is expected. - getOffset: get/setOffset was implemented on user request. It was originally not planned. It is not meant to be used in any calculations (although you could do, of course). It is meant to get the current offset , store it in some variable and restore it later. This can sometime be useful in a complicated data structure.
from binary-file-viewer.
- Sorry this is my missunderstanding, but then in the documentation it is written:,
If negative the offset is moved backwards.
I believe this actually contradicts with what you have just said. Please do amend either one of them. (What if I just wanted data in the range [-7:-4]?) - Correct me if I am wrong, but I cannot directly use the value from
getOffset
intosetOffset
because (getOffset()
andlastOffset
are equivalent) a normalread()
is staring fromlastOffset + lastSize
, butsetOffset
changes the variablelastSize
into zero. This simply means:
read(10);
setOffset(getOffset());
read(1);
will not give me the same result as:
read(10);
read(1);
Am I correct?
from binary-file-viewer.
-
If negative the offset is moved backwards
that is true. The problem is that the next read will add the absolute size.
I.e. the pointer is exactly where it was before.
I agree that this functionality might not be very useful. The 'read()' functionality was designed to be used with positive numbers.
It can deal with a negative value, but probably you can't do anything meaningful with it.
Is this (the negative size) really something you would want to use in a real project? -
Let's say the current pointer is at 5 and you do a read(10) then the current pointer stays at 5.
If you use getOffset() it returns 5. And if you setOffset(5) it just stays where it is, but clearing the size.
I.e. the next read(1) returns the value at offset 5.
To achieve what you want you would need to do the following:
read(10);
read(0); // would move the pointer to 15 in my example
setOffset(getOffset());
read(1);
from binary-file-viewer.
I don't need to use the negative offset currently, I just needed the getOffset(), but then I find it weird when I was testing the getOffset. The workaround you provided in point 2 does work, so I guess I'll just use that method. Both of them are counter intuitive to me so I decided to report, but then feel free to close this issue if you find it alright!
from binary-file-viewer.
Related Issues (16)
- Where is the JS file path? HOT 2
- Feature Request: support ${workspaceFolder} ? HOT 12
- Feature Request: View in Hex Editor HOT 1
- [Question] Where are the standard library objects such as Array or Object? HOT 9
- Getting the file size HOT 8
- Viewing of Packed Files HOT 1
- Zoom in charts not working.
- Signed / Unsigned number HOT 9
- Navigation seems not work? HOT 2
- Question: Changing values HOT 1
- Reading data from any file position HOT 10
- How to read float value? HOT 5
- Can't use a variable with the read() function HOT 8
- How to change parser? HOT 10
- Updating the view HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from binary-file-viewer.