summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/cli/src/ui/utils')
-rw-r--r--packages/cli/src/ui/utils/textUtils.test.ts41
-rw-r--r--packages/cli/src/ui/utils/textUtils.ts29
2 files changed, 0 insertions, 70 deletions
diff --git a/packages/cli/src/ui/utils/textUtils.test.ts b/packages/cli/src/ui/utils/textUtils.test.ts
deleted file mode 100644
index 5dd08875..00000000
--- a/packages/cli/src/ui/utils/textUtils.test.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * @license
- * Copyright 2025 Google LLC
- * SPDX-License-Identifier: Apache-2.0
- */
-
-import { isBinary } from './textUtils';
-
-describe('textUtils', () => {
- describe('isBinary', () => {
- it('should return true for a buffer containing a null byte', () => {
- const buffer = Buffer.from([
- 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x1a, 0x0a, 0x00,
- ]);
- expect(isBinary(buffer)).toBe(true);
- });
-
- it('should return false for a buffer containing only text', () => {
- const buffer = Buffer.from('This is a test string.');
- expect(isBinary(buffer)).toBe(false);
- });
-
- it('should return false for an empty buffer', () => {
- const buffer = Buffer.from([]);
- expect(isBinary(buffer)).toBe(false);
- });
-
- it('should return false for a null or undefined buffer', () => {
- expect(isBinary(null)).toBe(false);
- expect(isBinary(undefined)).toBe(false);
- });
-
- it('should only check the sample size', () => {
- const longBufferWithNullByteAtEnd = Buffer.concat([
- Buffer.from('a'.repeat(1024)),
- Buffer.from([0x00]),
- ]);
- expect(isBinary(longBufferWithNullByteAtEnd, 512)).toBe(false);
- });
- });
-});
diff --git a/packages/cli/src/ui/utils/textUtils.ts b/packages/cli/src/ui/utils/textUtils.ts
index fa0abe9a..e4d8ea58 100644
--- a/packages/cli/src/ui/utils/textUtils.ts
+++ b/packages/cli/src/ui/utils/textUtils.ts
@@ -17,35 +17,6 @@ export const getAsciiArtWidth = (asciiArt: string): number => {
return Math.max(...lines.map((line) => line.length));
};
-/**
- * Checks if a Buffer is likely binary by testing for the presence of a NULL byte.
- * The presence of a NULL byte is a strong indicator that the data is not plain text.
- * @param data The Buffer to check.
- * @param sampleSize The number of bytes from the start of the buffer to test.
- * @returns True if a NULL byte is found, false otherwise.
- */
-export function isBinary(
- data: Buffer | null | undefined,
- sampleSize = 512,
-): boolean {
- if (!data) {
- return false;
- }
-
- const sample = data.length > sampleSize ? data.subarray(0, sampleSize) : data;
-
- for (const byte of sample) {
- // The presence of a NULL byte (0x00) is one of the most reliable
- // indicators of a binary file. Text files should not contain them.
- if (byte === 0) {
- return true;
- }
- }
-
- // If no NULL bytes were found in the sample, we assume it's text.
- return false;
-}
-
/*
* -------------------------------------------------------------------------
* Unicode‑aware helpers (work at the code‑point level rather than UTF‑16