Skip to content

Overriding util.fetch to load files from zip bundle #684

@delapavap

Description

@delapavap

protobuf.js version: 6.3.3
Hi, This is a Question not an issue..., I'm trying to create a monkey patch to override util.fetch function because I need to load .proto files from a zip bundle. the thing is, I have a .proto with two imports (3 files to load in total) so.. When I check root object after load (promise way), the file's array contains all 3 files which means they are loaded correctly, but when I check all the way through nested objects I can figure out that last imported file wasn't processed. I'm using this function to override util.fetch

    BundleCache.prototype.fetchFromSimpleBundle = function (zip) {
            return function fetch(filename, options, callback) {
                try {
                    if (typeof options === "function") {
                        callback = options;
                        options = {};
                    } else if (!options)
                        options = {};

                    var proto = zip.file(filename);
                    var content = proto ? proto.asBinary() : null;
                    callback(null, content);
                } catch (error) {
                    callback(error);
                }
            };
        };

what am I missing or doing wrong?

I'm using nodeJs 4.6.0 btw.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions