How to correctly read and write any file in Jacascript?

I am building a form that allows a user to upload any file. Unfortunately, the file comes out distorted for non-simple file types such as .pdf (it works for simple .txt).

To test out that I am reading files correctly, I am using the following helper, as per this:

const makefile = (content: string) => {
  // Create element with <a> tag
  const link = document.createElement("a");

  // Create a blog object with the file content which you want to add to the file
  const file = new Blob([content], { type: "application/pdf" });

  // Add file content in the object URL
  link.href = URL.createObjectURL(file);

  // Add file name
  link.download = "sample.pdf";

  // Add click event to <a> tag to save file.
  link.click();
  URL.revokeObjectURL(link.href);
};

The helper creates an output file from the fed-in content.

I am reading and writing the file with:

  const onFinish = async (values: FormProps) => {
    const file = values.file?.originFileObj; // File type
    const reader = new FileReader();
    reader.addEventListener("load", (event) => {
      const binaryString = event.target?.result as string;
      makefile(binaryString);
    });

    if (!file) {
      return;
    }

    reader.readAsBinaryString(file);
  };

If everything works correctly, the downloaded sample.pdf should be identical to the input file read from the reader. However, that is not the case for more involved file types, such as .pdf.

The resulting file is corrupted and pdf readers can’t read it. It also comes out greater in size than the input file (for instance, 326KB output file size vs 222KB input file size).

I have tried different ways of reading the file, to no avail – all produce invalid output. What could be the issue?