in packages/web-ide-fs/src/browserfs/GitLabReadableFileSystem.ts [203:235]
public readFile(
fname: string,
encoding: string,
flag: FileFlag,
cb: BFSCallback<string | Buffer>,
): void {
// Get file.
// eslint-disable-next-line consistent-return
this.open(fname, flag, 0x1a4, (err: ApiError | undefined | null, fd?: File) => {
if (err) {
return cb(err);
}
const fdCast = <NoSyncFile<GitLabReadableFileSystem>>fd;
const fdBuff = <Buffer>fdCast.getBuffer();
if (encoding === null) {
cb(null, copyingSlice(fdBuff));
} else {
try {
const str = fdBuff.toString(<BufferEncoding>encoding);
cb(null, str);
} catch {
cb(
new ApiError(
ErrorCode.EINVAL,
`Could not convert buffer to string (path: ${fname}, encoding: ${encoding})`,
),
);
}
}
});
}