Skip to content

Commit

Permalink
[data][bfetch] Avoid using Buffer in client code (#107278)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant authored Aug 2, 2021
1 parent 47f5f81 commit 0c69b10
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pageLoadAssetSize:
dashboard: 374194
dashboardEnhanced: 65646
dashboardMode: 22716
data: 943821
data: 900000
dataEnhanced: 50420
devTools: 38637
discover: 99999
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/bfetch/public/streaming/inflate_response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
*/

import { unzlibSync, strFromU8 } from 'fflate';
import { toByteArray } from 'base64-js';

export function inflateResponse<Result extends object>(response: string) {
const buff = Buffer.from(response, 'base64');
const buff = toByteArray(response);
const unzip = unzlibSync(buff);
return strFromU8(unzip);
}
6 changes: 4 additions & 2 deletions src/plugins/data/common/field_formats/converters/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import escape from 'lodash/escape';
import { escape } from 'lodash';
import { i18n } from '@kbn/i18n';
import { KBN_FIELD_TYPES } from '@kbn/field-types';
import { asPrettyString, getHighlightHtml } from '../utils';
Expand Down Expand Up @@ -95,7 +95,9 @@ export class StringFormat extends FieldFormat {

private base64Decode(val: string) {
try {
return Buffer.from(val, 'base64').toString('utf8');
if (window && window.atob) return window.atob(val);
// referencing from `global` tricks webpack to not include `Buffer` polyfill into this bundle
return global.Buffer.from(val, 'base64').toString('utf8');
} catch (e) {
return asPrettyString(val);
}
Expand Down

0 comments on commit 0c69b10

Please sign in to comment.