#!/bin/bash

# Base URL for the chunked files
BASE_URL="https://huggingface.co/datasets/juannat7/ChaosBench/resolve/main/$1/"

# The base name of the files (without extension)
BASE_NAME="$1_chunks"

# Extension for the chunked files
EXTENSION="zip"

# Download all chunked files
wget "${BASE_URL}${BASE_NAME}.${EXTENSION}"
for i in $(seq -f "%02g" 1 99); do
    FILE_NAME="${BASE_URL}${BASE_NAME}.z${i}"
    wget "${FILE_NAME}" || break
done

# Combine the chunked files
zip -F "${BASE_NAME}.${EXTENSION}" --out "$1".zip

# Remove the chunked files
rm "${BASE_NAME}.${EXTENSION}"
for i in $(seq -f "%02g" 1 99); do
    rm "${BASE_NAME}.z${i}" || break
done

# Unzip the combined file
unzip "$1".zip

# Remove the combined zip file
rm "$1".zip