hometools

Split a File into Multiple Collections of Bytes

April 2026

This started as an idea for how to split up files so they don't get ingested by scrapper bots. It turns one file into two with every other byte going to the alternate file from the one before it. These can then be reassembled in WASM on the front-end.

Then, I realized I could just encrypt the files. They could be decoded automatically by simply including the password in the javascript on the page. Or, you could set up a form so that only folks with the password could get them.

I really like that idea in general. Basically, a way to serve encrypted content on a static site. I built a prototype of that here: Password Protecting Static Site Content with WASM.

In the mean time, here's the code that does the split.

src/main.rs
use anyhow::Result;
use std::fs;
use std::path::Path;
use std::path::PathBuf;

fn main() -> Result<()> {
  println!("Unzipping file bytes");
  let input_file = PathBuf::from("samples/church-3818213.webm");
  let output_dir = PathBuf::from("samples/output");
  unzip_file_bytes(&input_file, &output_dir)?;
  Ok(())
}

fn unzip_file_bytes(
  input_file: &PathBuf,
  output_dir: &Path,
) -> Result<()> {
  let bytes = fs::read(input_file)?;

  let mut alfa = vec![];
  let mut bravo = vec![];
  bytes.iter().enumerate().for_each(|(index, value)| {
    if index % 2 == 0 {
      alfa.push(*value);
    } else {
      bravo.push(*value);
    }
  });

  let alfa_out = output_dir.join("alfa");
  let bravo_out = output_dir.join("bravo");
  fs::write(alfa_out, alfa)?;
  fs::write(bravo_out, bravo)?;
  println!("Done");
  Ok(())
}
Cargo.toml
[package]
name = "unzip_a_file"
version = "0.1.0"
edition = "2024"

[dependencies]
anyhow = "1.0.102"

I haven't written the re-assembly code yet since I'm going with encryption. I don't expect it to be difficult if I come back to it.

-a