Skip to content

How to get a Buffer instead of a Blob? #7

@lycpan233

Description

@lycpan233

I'm in a Node environment, asBlob gets a Blob object. I expect a buffer, how do I configure it?

    const blob = await HtmlDocx.asBlob(htmlText);

I noticed the presence of the global attribute, but I don't know how to change it

  generateDocument: function(zip) {
    var buffer;
    buffer = zip.generate({
      type: 'arraybuffer'
    });
    if (global.Blob) {
      return new Blob([buffer], {
        type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
      });
    } else if (global.Buffer) {
      return new Buffer(new Uint8Array(buffer));
    } else {
      throw new Error("Neither Blob nor Buffer are accessible in this environment. " + "Consider adding Blob.js shim");
    }
  },

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