Skip to content

Commit d6c6b2e

Browse files
committed
Switched to arraybuffer response + manuel decoding using TextDecoder
1 parent 34a218a commit d6c6b2e

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

adapter/src/adapter/importer/HttpImporter.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { TextDecoder } from 'util';
2+
13
import axios, { AxiosError } from 'axios';
24

35
import { ImporterParameterError } from '../exceptions/ImporterParameterError';
@@ -64,23 +66,19 @@ export class HttpImporter extends Importer {
6466
override async doFetch(parameters: Record<string, unknown>): Promise<string> {
6567
const uri = parameters.location as string;
6668
const encoding = parameters.encoding as string;
69+
const decoder = new TextDecoder(encoding);
6770

68-
// The old impl retrieved data as byte array and then converted using encoding:
69-
// Return new String(rawResponse, Charset.forName((String) parameters.get("encoding")));
70-
// Unfortunately there does not seem to be a universal method .toString(encoding?: string) in javascript
71+
// Fetch as ArrayBuffer
7172
const result = await axios
72-
.get(uri, { responseEncoding: encoding })
73+
.get(uri, { responseType: 'arraybuffer' })
7374
.catch((error: AxiosError) => {
7475
if (error.response) {
7576
console.log(error.response);
7677
throw new Error('Could not Fetch from URI:' + uri);
7778
}
7879
throw new ImporterParameterError('Could not Fetch from URI:' + uri);
7980
});
80-
// Check if data is object/array -> return stringified (because this method returns string)
81-
if (typeof result.data === 'object' || Array.isArray(result.data)) {
82-
return JSON.stringify(result.data);
83-
}
84-
return result.data as string;
81+
// Convert ArrayBuffer response to string using encoding
82+
return decoder.decode(result.data);
8583
}
8684
}

0 commit comments

Comments
 (0)