I cant write buffer to a file

44 views Asked by At

I am trying to get dto from the params then convert it to the buffered data and write it to a file but it writes data to file as json again. What could be the problem here?

async import(dto: ImportDto, veritabaniId: number): Promise<Buffer> {
const quadDto = new QuadBulkCreateDto();
quadDto.quads = JSON.parse(dto.file.data);

try {
  await validate(quadDto);
  const dirPath = join(envConfig.quadsDataPath, veritabaniId.toString());
  const filePath = join(dirPath, 'quad_data.json');

  await fs.promises.mkdir(dirPath, { recursive: true });

  const binaryFile = Buffer.from(JSON.stringify(quadDto.quads));

  await fs.promises.writeFile(filePath, binaryFile);

  const fileData = await fs.promises.readFile(filePath);

  return fileData;
} catch (error) {
  throw error;
}

}

0

There are 0 answers