Node - fs.readdir does not work in files with special characters

I am having problems with a function fs.readdirwhen I want to get directory files. I used different encodings to avoid this, but I cannot solve it.

For example, I used this directory to try it.

enter image description here

Look at the last file, it has a special character and fs.readdirreturns12 - Un país con el nombre de un río.mp3

I just use this code to read the directory:

import fs from 'fs';
import {promisify} from 'util';

const readdir = promisify(fs.readdir);

const {err, names} = await readdir('path/to/dir');

Node version: node8-alpine

Is there any way to solve it?

Thanks in advance!

+4
source share

Source: https://habr.com/ru/post/1694866/


All Articles