function createReadStreamOrReadFileSync(
  filename,
  outputFileSystem,
  start,
  end,
) {
  /** @type {string | Buffer | import("fs").ReadStream} */
  let bufferOrStream;
  /** @type {number} */
  let byteLength;

  // Stream logic
  const isFsSupportsStream =
    typeof outputFileSystem.createReadStream === "function";

  if (isFsSupportsStream) {
    bufferOrStream =
      /** @type {import("fs").createReadStream} */
      (outputFileSystem.createReadStream)(filename, {
        start,
        end,
      });

    // Handle files with zero bytes
    byteLength = end === 0 ? 0 : end - start + 1;
  } else {
    bufferOrStream = outputFileSystem.readFileSync(filename);
    ({ byteLength } = bufferOrStream);
  }

  return { bufferOrStream, byteLength };
}
@param {string} filename filename
@param {OutputFileSystem} outputFileSystem output file system
@param {number} start start
@param {number} end end
@returns {{ bufferOrStream: (Buffer | import("fs").ReadStream), byteLength: number }} result with buffer or stream and byte length