Change Buffer.from to window.btoa
Signed-off-by: MALIN WIDÈN <malwi130@student.liu.se>
This commit is contained in:
@@ -25,7 +25,7 @@ describe('base64EncodeContent', () => {
|
||||
it('encodes text files', () => {
|
||||
expect(base64EncodeContent('abc')).toBe('YWJj');
|
||||
expect(base64EncodeContent('abc'.repeat(1000000))).toBe(
|
||||
Buffer.from('<file too large>').toString('base64'),
|
||||
window.btoa('<file too large>'),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -38,7 +38,7 @@ describe('base64EncodeContent', () => {
|
||||
);
|
||||
// Triggers size check
|
||||
expect(base64EncodeContent('😅'.repeat(1000000))).toBe(
|
||||
Buffer.from('<file too large>').toString('base64'),
|
||||
window.btoa('<file too large>'),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -59,11 +59,11 @@ interface DryRunProviderProps {
|
||||
|
||||
export function base64EncodeContent(content: string): string {
|
||||
if (content.length > MAX_CONTENT_SIZE) {
|
||||
return Buffer.from('<file too large>').toString('base64');
|
||||
return window.btoa('<file too large>');
|
||||
}
|
||||
|
||||
try {
|
||||
return Buffer.from(content).toString('base64');
|
||||
return window.btoa(content);
|
||||
} catch {
|
||||
const decoder = new TextEncoder();
|
||||
const buffer = decoder.encode(content);
|
||||
@@ -74,7 +74,7 @@ export function base64EncodeContent(content: string): string {
|
||||
String.fromCharCode(...buffer.slice(offset, offset + CHUNK_SIZE)),
|
||||
);
|
||||
}
|
||||
return Buffer.from(chunks.join('')).toString('base64');
|
||||
return window.btoa(chunks.join(''));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -58,8 +58,7 @@ describe('DryRunResultsView', () => {
|
||||
directoryContents: [
|
||||
{
|
||||
path: 'foo.txt',
|
||||
base64Content:
|
||||
Buffer.from('Foo Content').toString('base64'),
|
||||
base64Content: window.btoa('Foo Content'),
|
||||
executable: false,
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user