Giter Club home page Giter Club logo

Comments (5)

JeffreyCheung0429 avatar JeffreyCheung0429 commented on June 18, 2024

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.

maziac avatar maziac commented on June 18, 2024

Hi,

  1. 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.
  2. 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.

JeffreyCheung0429 avatar JeffreyCheung0429 commented on June 18, 2024
  1. 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]?)
  2. Correct me if I am wrong, but I cannot directly use the value from getOffset into setOffset because (getOffset() and lastOffset are equivalent) a normal read() is staring from lastOffset + lastSize, but setOffset changes the variable lastSize 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.

maziac avatar maziac commented on June 18, 2024
  1. 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?

  2. 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.

JeffreyCheung0429 avatar JeffreyCheung0429 commented on June 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.