<commit_before>import * as fs from 'fs';
import {promisify} from 'util';

const statAsync = promisify(fs.stat);
const openAsync = promisify(fs.open);
const closeAsync = promisify(fs.close);

const MAX_BYTES = 512

export async function isBinaryFile(file: string | Buffer, size?: number): Promise<boolean> {
  if (isString(file)) {
    const filepath = file;

    const stat = await statAsync(filepath);

    if (!stat.isFile()) {
      throw new Error(`Path provided was not a file!`);
    }

    const fileDescriptor = await openAsync(filepath, 'r');

    const allocBuffer = Buffer.alloc(MAX_BYTES);

    // Read the file with no encoding for raw buffer access.<commit_msg>gross I thought I got rid of this<commit_after>import * as fs from 'fs';
import {promisify} from 'util';

const statAsync = promisify(fs.stat);
const openAsync = promisify(fs.open);
const closeAsync = promisify(fs.close);

const MAX_BYTES = 512

export async function isBinaryFile(file: string | Buffer, size?: number): Promise<boolean> {
  if (isString(file)) {
    const stat = await statAsync(file);

    if (!stat.isFile()) {
      throw new Error(`Path provided was not a file!`);
    }

    const fileDescriptor = await openAsync(file, 'r');

    const allocBuffer = Buffer.alloc(MAX_BYTES);

    // Read the file with no encoding for raw buffer access.
{'fraction_non_alphanumeric': 0.11694152923538231, 'fraction_numerical': 0.004497751124437781, 'mean_word_length': 4.037735849056604, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2676309', 'n_tokens_mistral': 417, 'n_tokens_neox': 403, 'n_words': 137}