jDataView / jBinary

High-level API for working with binary data.
jdataview.github.io/jBinary/
MIT License
540 stars 56 forks source link

im noob #53

Open estantaya opened 8 years ago

estantaya commented 8 years ago

it is possible?

var typeSet = {

    jBinary.all:'msh',

    msh: {
        artworks: ['string0', 9],
        version: ['array', 'uint8', 8],
        indices: ['array', 'uint8', 8],

        versionName: ['string0', 'indices[4]']
    }
};

'indices[4]' as variable

RReverser commented 8 years ago

I don't know what you're trying to achieve, so can't answer your question. Also, please format your code using Markdown for better readability (wrap between ```javascript and ````` lines).

estantaya commented 8 years ago

sry 'indices[4]' as variable???? i use this for the moment

var typeSet = {
    artworks: ['string0', 9],
    version: ['array', 'uint8', 8],
    indices: ['array', 'uint8', 8],
};
    jBinary.load(files[0], typeSet, function (err, binary) {
        //var tar = binary.readAll;
        //console.log(tar);
        document.getElementById("empresa").value=binary.read('artworks');
        document.getElementById("version").value=binary.read('version');
        var indices=binary.read('indices');
        document.getElementById("indices").value=indices;
        document.getElementById("titulo").value=binary.read(['string0',indices[4]]);
        binary.skip(4);
        var color=binary.read(['array', 'uint8', 4]);
        for (i=0;i<color.length;i++) {
            document.getElementById("color"+i).value=color[i];
        }
    });
RReverser commented 8 years ago

Now I see. No, you can't use ['string0', 'indices[4]'] directly, but you can pass a function from context as a second argument, see https://github.com/jDataView/jBinary/wiki/Standard-types#references for an example.

In your case, it will be smth like:

    msh: {
        artworks: ['string0', 9],
        version: ['array', 'uint8', 8],
        indices: ['array', 'uint8', 8],

        versionName: ['string0', function (context) {
            return context.indices[4];
        });
    }

or, if using ES6, ['string0', context => context.indices[4]].

Does this answer your question?

estantaya commented 8 years ago

TypeError: Size is not a number. if("number"!=typeof b)throw new TypeError("Size is not a number.");

var typeSet = {
    company: ['string0', 9],
    version: ['array', 'uint8', 8],
    indices: ['array', 'uint8', 8],
    versionName: ['string0', function (context) {
            return context.indices[4];
    }],
    color: ['array', 'uint8', 4]
};

input[5]=htmlEscape(binary.read('versionName'));

it does not work that way but I have no trouble reading the binary and arrays :) I will return when I have trouble writing the data muahahaha

RReverser commented 8 years ago

That's strange, can you do console.log(context) inside of that function (context) { ... } and tell what you see?

estantaya commented 8 years ago

trow the same thing