Unable to run modified torrent file: missing pieces hash after removing files

I’m trying to modify a torrent file by removing files with a specific file extension using the
torrent-parser library in Node.js. Here’s the code that I’m using:

import fs from "fs"; import { decodeTorrentFile, decodeTorrent, encodeTorrent, parseInfo, from "torrent-parser";

const torrent = fs.readFileSync("test_torrent.torrent");

let parsedTorrent = decodeTorrent(torrent);

Modify the torrent file by removing files with “.srt” extension

parsedTorrent.files = parsedTorrent.files.filter( (file) => file.name.includes(".srt") ); parsedTorrent.info.files = parsedTorrent.info.files.filter( (file) => !file.path.toString("utf8").includes(".srt") );

Encode the modified torrent and write to disk

encodeTorrent(parsedTorrent, "./modified_torrent.torrent")

The code runs without any errors and generates a new torrent file with the modified list of files. However, when I try to open the new torrent file in a torrent client, I get an error message saying:

“Unable to run this torrent: torrent contains no piece hashes”

. I suspect that the problem might be related to the modification of the torrent file, but I’m not sure how to fix it.

Any help or suggestions would be greatly appreciated. Thank you!