Using createReadStream(), I'm attempting to stream a CSV file stored in my program's directory, however, it seems to be returning a buffer with a string of the file's bytes, as opposed to the actual text content. I was of the impression that readFile() was used for buffering files, while createReadStream() would stream the file. Perhaps I'm just ignorant to the way the streams truly work.
At this point, I'm simply outputting the data to see what the program is streaming. Code is as follows:
const fs = require("fs");
const path = require("path");
// These variables set the filepath of the CSV file
const basePath = "./"
const fileName = "dummy.csv"
// Create the path string
const fileLoc = path.join(basePath, fileName);
console.log(fileLoc);
fs.createReadStream(fileLoc).on("data", (data) => { console.log(data); })
Output:
<Buffer 54 49 54 4c 45 2c 20 41 52 54 49 53 54 2c 20 59 45 41 52 0d 0a 43 61 6e 20 59 6f 75 20 46 65 65 6c 20 4d 79 20 48 65 61 72 74 2c 20 42 72 69 6e 67 20 ... 122 more bytes>
Note that I haven't piped the data - this is because I can't think of what writable stream to pipe the data to, or what I would need to do to create one. My issue may well lie here.
Thanks in advance
buf.toString(...).SOLVEDin the title or to put the solution in your question. That is not how things work here. Questions are only for questions, not answers. Answers go in answers. You can even post an answer to your own question if you want. Please edit your question to remove the solution and "solved" stuff. I've posted an answer that you can accept by clicking the checkmark to the left of it to indicate to the community that your question has been answered and is done. That's the proper procedure here.