I have a simple Node app with a function that downloads a WordPress theme zip file and console logs the contents of the theme.json
file.
const StreamZip = require('node-stream-zip');
var AdmZip = require("adm-zip");
const axios = require('axios');
const f = async () => {
const url = 'https://downloads.wordpress.org/theme/twentytwentytwo.1.2.zip';
const body = await axios.get(url, {
responseType: 'arraybuffer',
});
var zip = new AdmZip(body.data);
var zipEntries = zip.getEntries(); // an array of ZipEntry records
zipEntries.forEach(function (zipEntry) {
if (zipEntry.entryName == "twentytwentytwo/theme.json") {
const tp = zipEntry.getData();
const tmp = Buffer.from(tp, 'base64').toString('utf8')
console.log(tmp);
}
});
};
f();
However, as can be seen in the output below there are some unexpected characters included. I'm not sure what these are, or how to remove them from the output.
ä
"version": 2,
"customTemplates": Ä
ä
"name": "blank",
"title": "Blank",
"postTypes": Ä
"page",
"post"
Ü
ü,
ä
"name": "page-large-header",
"title": "Page (Large Header)",
"postTypes": Ä
"page"
Ü
ü,
ä
"name": "single-no-separators",
"title": "Single Post (No Separators)",
"postTypes": Ä
"post"
Ü
ü,
ä
"name": "page-no-separators",
"title": "Page (No Separators)",
"postTypes": Ä
"page"
Ü
ü
Ü,