fixed blob loading
This commit is contained in:
+18
-20
@@ -64,33 +64,31 @@ Hi01379 = (function(psGopherRequest) {
|
||||
|
||||
// resource format: [type, selector, host, port]
|
||||
function loadHole(resource, input, successCb, errorCb) {
|
||||
var fname = resource[1].split('/').pop(), // as the most intelligent guess
|
||||
ext = fname.split('.').pop().toLowerCase(), // presumed extension
|
||||
extMappings = { // not including AVIF here because they aren't supported by Gecko 48 anyway
|
||||
'gif': 'image/gif', // including GIF though because nothing prevents using I instead of g
|
||||
'png': 'image/png',
|
||||
'svg': 'image/svg+xml',
|
||||
'webp': 'image/webp',
|
||||
'apng': 'image/apng',
|
||||
'jpg': 'image/jpeg',
|
||||
'jpeg': 'image/jpeg',
|
||||
'jfif': 'image/jpeg',
|
||||
'pjpeg': 'image/jpeg',
|
||||
'pjp': 'image/jpeg'
|
||||
}
|
||||
psGopherRequest(resource, input, function(rawdata, type) {
|
||||
if(type == '5' || type == 's' || type == ';' || type == 'd')
|
||||
type = '9' // remap unknown binary types to 9
|
||||
if(type == '9' || type == 'g' || type == 'I') { // binary file
|
||||
var ctype = 'application/octet-stream' // the default one if everything else fails
|
||||
var datablob = new Blob([rawdata], {type: ctype}),
|
||||
fname = resource[1].split('/').pop() // as the most intelligent guess
|
||||
// update content type
|
||||
if(type == 'g') // GIF-only resource type
|
||||
ctype = 'image/gif'
|
||||
else if(type == 'I') { // attempt to guess the image MIME type by the extension
|
||||
var ext = fname.split('.').pop().toLowerCase(),
|
||||
extMappings = { // not including AVIF here because they aren't supported by Gecko 48 anyway
|
||||
'gif': 'image/gif', // including GIF though because nothing prevents using I instead of g
|
||||
'png': 'image/png',
|
||||
'svg': 'image/svg+xml',
|
||||
'webp': 'image/webp',
|
||||
'apng': 'image/apng',
|
||||
'jpg': 'image/jpeg',
|
||||
'jpeg': 'image/jpeg',
|
||||
'jfif': 'image/jpeg',
|
||||
'pjpeg': 'image/jpeg',
|
||||
'pjp': 'image/jpeg'
|
||||
}
|
||||
if(ext in extMappings)
|
||||
ctype = extMappings(ext)
|
||||
}
|
||||
else if(type == 'I') // attempt to guess the image MIME type by the extension
|
||||
ctype = extMappings[ext]
|
||||
var datablob = new Blob([rawdata], {type: ctype})
|
||||
successCb({
|
||||
content: datablob,
|
||||
contentType: ctype,
|
||||
@@ -100,7 +98,7 @@ Hi01379 = (function(psGopherRequest) {
|
||||
})
|
||||
}
|
||||
else { // assuming text content otherwise
|
||||
var output = decodeURIComponent(escape(rawdata)), ctype = 'text/plain' // defaulting to type 0
|
||||
var output = (new TextDecoder).decode(rawdata), ctype = 'text/plain' // defaulting to type 0
|
||||
if(type == '1' || type == '7') { // gophermap
|
||||
output = gophermapToHTML(output, resource[2], resource[3])
|
||||
ctype = 'text/html'
|
||||
|
||||
Reference in New Issue
Block a user