The usenet originally only consisted of text messages, but it soon became a way of exchanging binary files as well. As posts are usually restricted to only a few MB, larger archives have to be split up into several parts, each attached to its own newsgroup posting. But if some parts of these posts aren’t transferred correctly to other usenet hosts, the archive parts are broken.
Not necessarily if the poster created PAR2 archives in addition to the actual data archive parts. In a RAID-like manner, parity information is placed redundantly into the additional files. Thus, it is possible to recover the complete archive if some parts of it are incomplete.
As I downloaded some image archives (No, they were not p’rn) containing pictures in the PCD format that encapsulates six different resolutions of an image, I also had to find out how to explicitly extract the large (3072×2048) resolution out of it. All in all, I created the following (simple) script that
- checks the PAR2 files, and if some of the data archive parts are incomplete, it
- tries to recover them, and
- if check (or recovery) were successful, the PCD images are extracted and converted to JPEG.
I did it this way:
#!/bin/bash
# Verify, includes *PAR2 automatically
par2 v *par2
ret=$?
if [ $ret -eq 0 ]; then
# Extract
unrar x *part01.rar
cd “$(find -type d | tail -n 1)”
# Convert
for file in *PCD; do
echo -n “$file ”
convert $file[5] $(basename $file .PCD).jpg && rm $file
done
echo Done.
elif [ $ret -eq 1 ]; then
echo “PARITY CHECK FAILED, TRYING TO REPAIR.”
sleep 2
# Repair, if needed
par2 r *par2 && echo “You may now rerun this script.”
else
echo “REPAIR NOT POSSIBLE.”
fi