Skip to content

Instantly share code, notes, and snippets.

@nicolaair
nicolaair / decodeResponse.js
Created January 25, 2024 12:15 — forked from arimariojesus/decodeResponse.js
Decode a xml fetch response with ISO-8859-1 codification to UTF-8
const decodedResponse = await fetch('https://www.anysite.rss.xml', {
headers: {
'Content-Type': 'text/xml;charset=ISO-8859-1',
},
})
.then(r => r.arrayBuffer()) // resolve the response stream for buffer
.then(d => {
const dataView = new DataView(d); // creates a DataView object representing the buffer data
const isoDecoder = new TextDecoder('ISO-8859-1'); // creates an instance of the our decoder
const decodedString = isoDecoder.decode(dataView); // so we pass the stream of bytes for the decoder do its job
@nicolaair
nicolaair / go-os.exist
Last active September 12, 2018 19:08 — forked from mattes/check.go
Go (Golang) check if file or directory exists
if _, err := os.Stat("/path/to/whatever"); os.IsNotExist(err) {
// path/to/whatever does not exist
}
if _, err := os.Stat("/path/to/whatever"); err == nil {
// path/to/whatever exists
}