Skip to content

Commit 36910cb

Browse files
authored
feat: Implement file RAM bundles (#18)
1 parent 872d44b commit 36910cb

File tree

8 files changed

+316
-49
lines changed

8 files changed

+316
-49
lines changed

examples/split_ram_bundle.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
use std::env;
22
use std::fs;
33
use std::fs::File;
4-
use std::io::Read;
54
use std::path::Path;
65

7-
use sourcemap::ram_bundle::{split_ram_bundle, RamBundle};
6+
use sourcemap::ram_bundle::{split_ram_bundle, RamBundle, RamBundleType};
87
use sourcemap::SourceMapIndex;
98

9+
const USAGE: &str = "
10+
Usage:
11+
./split_ram_bundle RAM_BUNDLE SOURCEMAP OUT_DIRECTORY
12+
13+
This example app splits the given RAM bundle and the sourcemap into a set of
14+
source files and their sourcemaps.
15+
16+
Both indexed and file RAM bundles are supported.
17+
";
18+
1019
fn main() -> Result<(), Box<std::error::Error>> {
1120
let args: Vec<_> = env::args().collect();
1221
if args.len() < 4 {
13-
panic!("Usage: ./split_ram_bundle RAM_BUNDLE SOURCEMAP OUT_DIRECTORY");
22+
println!("{}", USAGE);
23+
std::process::exit(1);
1424
}
1525

16-
let mut bundle_file = File::open(&args[1])?;
17-
let mut bundle_data = Vec::new();
18-
bundle_file.read_to_end(&mut bundle_data)?;
19-
let ram_bundle = RamBundle::parse(&bundle_data).unwrap();
26+
let bundle_path = Path::new(&args[1]);
27+
let ram_bundle = RamBundle::parse_indexed_from_path(bundle_path)
28+
.or_else(|_| RamBundle::parse_unbundle_from_path(bundle_path))?;
29+
30+
match ram_bundle.bundle_type() {
31+
RamBundleType::Indexed => println!("Indexed RAM Bundle detected"),
32+
RamBundleType::Unbundle => println!("File RAM Bundle detected"),
33+
}
2034

2135
let sourcemap_file = File::open(&args[2])?;
2236
let ism = SourceMapIndex::from_reader(sourcemap_file).unwrap();
@@ -41,6 +55,7 @@ fn main() -> Result<(), Box<std::error::Error>> {
4155
let out_sm = File::create(output_directory.join(sourcemap_name))?;
4256
sm.to_writer(out_sm)?;
4357
}
58+
println!("Done.");
4459

4560
Ok(())
4661
}

0 commit comments

Comments
 (0)