jprichardson / node-fs-extra

Node.js: extra methods for the fs object like copy(), remove(), mkdirs()
MIT License
9.43k stars 775 forks source link

Getting docx file in corrupted format when created from xmlstring #1040

Closed beingvishalt closed 4 months ago

beingvishalt commented 4 months ago

To Reproduce 1) I created xml file from docx (this docx contain just one word which is hello) using node-stream-zip npm package using StreamZip function. 2) then I read that xml using fs npm package and stored that in one variable as string.

  const xmlBuffer = fs.readFileSync(xmlFileName);
  const xmlContent = xmlBuffer.toString('utf-8');  // here xml content is read correctly

3) now i want to convert back that xml to docx file, so I used fs package

 fs.writeFile('output.docx', xmlContent, err => {
    if (err) {
      console.error('Error writing DOCX file:', err);
      return;
    }
    console.log('DOCX file created successfully!');
  });

word file is generated but it is in corrupted form, and when try to open that docx file in notepad i am able to see exact xml that come in variable xmlContent PFA, image image

RyanZim commented 4 months ago

The methods you're using are Node.js core fs methods, not fs-extra-specific additions. I suggest trying to get help with your problem on https://stackoverflow.com/