Skip to content

Inject metadata/extra fields into the build *.tgz file #21

@mStirner

Description

@mStirner
const insertExtraFields = (data, fields) => {
    let fullLength = 0;
    for (const field in fields) {
        const si2 = field >> 8;
        if (!si2 || si2 > 255) {
            throw new Error('The extra IDs must be greater than 255 and less than 65536');
        }
        fullLength += fields[field].length + 4;
    }
    if (fullLength > 65535) {
        throw new Error(
            'The total size of the extra header is '
            + fullLength
            + ' bytes, but it must be at most 65535 bytes'
        );
    }
    const afterExtra = data.subarray(10);
    const out = new Uint8Array(12 + fullLength + afterExtra.length);
    out.set(data.subarray(0, 10));
    out.set(afterExtra, out.length - afterExtra.length);
    // Enable FEXTRA
    out[3] |= 4;
    out[10] = fullLength & 255;
    out[11] = fullLength >> 8;
    let b = 12;
    for (const field in fields) {
        out[b] = field & 255;
        out[b + 1] = field >> 8;
        const ext = fields[field];
        out[b + 2] = ext.length & 255;
        out[b + 3] = ext.length >> 8;
        out.set(ext, b + 4);
        b += ext.length + 4;
    }
    return out;
}

const asciiToID = str => {
    if (str.length != 2) throw new TypeError('extra ID must be two characters long');
    return str.charCodeAt(0) | (str.charCodeAt(1) << 8);
  }

module.exports = {
    insertExtraFields,
    asciiToID
};

https://github.com/OpenHausIO/playground/tree/main/plugin-wrapper-tgz-meta-data
https://github.com/OpenHausIO/playground/tree/main/tgz-plugin-creation
101arrowz/fflate#82

Before implementing that, we should ask for intents from the wizard (#9) and save metadata.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions