2026-03-26 12:30:54 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2026 Element Creations Ltd.
|
|
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { dirname, join } from "node:path";
|
|
|
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
|
import { readFile } from "node:fs/promises";
|
|
|
|
|
import { readFileSync } from "node:fs";
|
|
|
|
|
|
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
|
|
|
|
|
|
|
export function getSampleFilePath(file: string): string {
|
|
|
|
|
return join(__dirname, file);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-08 11:51:53 +01:00
|
|
|
export function readSampleFile(file: string, encoding: null): Promise<Buffer>;
|
2026-03-26 12:30:54 +01:00
|
|
|
export function readSampleFile(file: string, encoding?: BufferEncoding): Promise<string>;
|
2026-06-08 11:51:53 +01:00
|
|
|
export function readSampleFile(file: string, encoding: BufferEncoding | null = "utf-8"): Promise<Buffer | string> {
|
2026-03-26 12:30:54 +01:00
|
|
|
return readFile(getSampleFilePath(file), encoding);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-08 11:51:53 +01:00
|
|
|
export function readSampleFileSync(file: string, encoding: null): Buffer;
|
2026-03-26 12:30:54 +01:00
|
|
|
export function readSampleFileSync(file: string, encoding?: BufferEncoding): string;
|
2026-06-08 11:51:53 +01:00
|
|
|
export function readSampleFileSync(file: string, encoding: BufferEncoding | null = "utf-8"): Buffer | string {
|
2026-03-26 12:30:54 +01:00
|
|
|
return readFileSync(getSampleFilePath(file), encoding);
|
|
|
|
|
}
|