Я пытаюсь прочитать текстовый файл и преобразовать его в объект javascript с помощью Node JS. Мой файл выглядит следующим образом:
Package: libseccomp2
Depends: libc6 (>= 2.14)
Description: high level interface to Linux seccomp filter
This library provides a high level interface to constructing, analyzing
and installing seccomp filters via a BPF passed to the Linux Kernel's
prctl() syscall.
Package: libperl5.26
Depends: libbz2-1.0, libc6 (>= 2.23), libdb5.3, libgdbm-compat4, libgdbm5 (>= 1.12), zlib1g (>= 1:1.2.2.3), perl-modules-5.26 (>= 5.26.1-6ubuntu0.3)
Description: shared Perl library
This package contains the shared Perl library, used by applications
which embed a Perl interpreter.
.
It also contains the architecture-dependent parts of the standard
library (and depends on perl-modules-5.26 which contains the
architecture-independent parts).
Я хотел вывести его так:
[{
Package: "libseccomp2",
Depends: ["libc6"]
Description: "high level interface to Linux seccomp filter
This library provides a high level interface to constructing, analyzing
and installing seccomp filters via a BPF passed to the Linux Kernel's
prctl() syscall."
},
{
Package: "libperl5.26",
Depends: ["libbz2-1.0", "libc6"]
Description: "high level interface to Linux seccomp filter
This library provides a high level interface to constructing, analyzing
and installing seccomp filters via a BPF passed to the Linux Kernel's
prctl() syscall."
}]
Это то, что у меня есть, но оно продолжает давать мне ошибки. Заранее благодарю за помощь
fs.readFile('file.txt', "utf8", (err, data) => {
if (err) {
console.error(err)
return
}
let obj = {};
let line = data.toString().split("\n");
for (let i = 0; i<line.length; i++) {
let newLine = line[i].split(":");
obj[newLine[0]] = newLine[1].split(" ");
}
console.log(obj);
})