Skip to content

Commit cb81d99

Browse files
committed
Show UTF-8 but 'binary' stream messages as text by default
1 parent 154d3e7 commit cb81d99

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/model/events/stream-message.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { computed, observable } from 'mobx';
22

33
import { InputStreamMessage } from "../../types";
4-
import { asBuffer } from '../../util/buffer';
4+
import { asBuffer, isProbablyUtf8 } from '../../util/buffer';
55
import { ObservableCache } from '../observable-cache';
66
import { isProbablyJson, isProbablyJsonRecords } from '../../util/json';
77

@@ -44,7 +44,7 @@ export class StreamMessage {
4444
}
4545

4646
get contentType() {
47-
if (this.inputMessage.isBinary) {
47+
if (this.inputMessage.isBinary && !isProbablyUtf8(this.inputMessage.content)) {
4848
if (this.subprotocol?.includes('proto')) {
4949
return 'protobuf';
5050
} else {

src/util/buffer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const binaryLaxDecoder = new TextDecoder('latin1', { fatal: false });
2121
// raw binary data). For viewing content as text we don't care (we just always show
2222
// as UTF8) but for _editing_ binary data we need a lossless encoding, not utf8.
2323
// (Monaco isn't perfectly lossless editing binary anyway, but we can try).
24-
export function isProbablyUtf8(buffer: Buffer) {
25-
let dataToCheck: Buffer;
24+
export function isProbablyUtf8(buffer: Uint8Array) {
25+
let dataToCheck: Uint8Array;
2626
if (buffer.byteLength > 1028) {
2727
// We want to trim the data to ~1KB, to avoid checking huge bodies in full.
2828
// Unfortunately, for UTF-8 this isn't safe: if a multibyte char crosses the

0 commit comments

Comments
 (0)