Download a piece #nd2: File does not exist : /tmp/torrents870514229/piece-9

I’m stuck at this error for a bit, i’m unable to save this piece in my system what am i doing wrong?

my code snippet for saving a piece

const fixLinuxPath = (location) => {
    if (location.startsWith('/tmp')) {
        // Replace with Windows temp directory
        return location.replace('/tmp', os.tmpdir());
    }
    return location;
};

const savePiece = (index, fullPiece, location) => {
    location = fixLinuxPath(location);  // Ensure location is compatible with Windows

    console.log(`Saving piece to: ${location}`);
    const pieceFile = path.join(location, `piece-${index}`); 
    console.log(pieceFile);

    // Create the directory if it doesn't exist
    fs.mkdir(path.dirname(pieceFile), { recursive: true }, (err) => {
        if (err) {
            console.error(`Error creating directory: ${err}`);
            return;
        }

        // Save the piece
        fs.writeFile(pieceFile, fullPiece, (err) => {
            if (err) {
                console.error(`Error saving piece ${index}:`, err);
            } else {
                console.log(`Piece ${index} saved to ${pieceFile}`);
            }
        });
    });
};

@Vishnu-VCheruvathery Could you upload your code to GitHub and share the link? It will be much easier to debug if I can run it directly.

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.