# resource/bunchasset (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/resource/bunchasset/

Bunch asset. (BunchAsset of the original resource/bunchasset.js)
- In the original it is a skeleton that inherits BlobAsset and only changes the asset type to bunch. Reading is the same as BlobAsset. (unpacking the bunch is not done yet)
- In the Rust version it is a struct with the same functions instead of inheritance, and the asset type is AssetType::Bunch.

## BunchAsset (struct) (Default, Asset)

Bunch asset.
- Reading and taking out are the same as BlobAsset, and only the asset type is bunch.

Example: Read with bytes in hand and check the asset type

```rust
use vanilla::{Asset, AssetType, BunchAsset};

let mut bunch_asset = BunchAsset::new();
assert_eq!(bunch_asset.get_asset_base().get_asset_type(), AssetType::Bunch);
bunch_asset.load_from_bytes("pack.bunch", vec![1, 2, 3]);
assert!(bunch_asset.is_loaded());
assert_eq!(bunch_asset.get_blob().expect("bytes").as_slice(), &[1, 2, 3]);
```

- `pub fn new() -> BunchAsset` (constructor, since 0.3.2): Creates one. (asset type bunch)
  - returns BunchAsset: Empty bunch asset before a request.
- `pub fn load(&mut self, engine: &Engine, asset_path: &str) -> AssetLoadHandle` (method, since 0.3.2): Requests a read. (the original load = BlobAsset.load, returns a load handle that can be awaited)
  - If already requested, does not request again and returns the first handle.
  - `engine` &Engine: Engine to ask for the bytes.
  - `asset_path` &str: Asset path. (relative to the asset folder on desktop, to asset_base_url on the web; data: URLs also work)
  - returns AssetLoadHandle: Load handle. (on desktop it is read on the spot and already finished. Finishes in failure if it cannot be read)
- `pub fn load_from_bytes(&mut self, asset_path: &str, bytes: Vec<u8>)` (method, since 0.3.2): Reads from bytes already in hand.
  - Replaces it with a new handle even if a requested handle exists.
  - `asset_path` &str: Path to record.
  - `bytes` Vec<u8>: Asset bytes.
- `pub fn unload(&mut self)` (method, since 0.3.2): Unloads.
- `pub fn get_blob(&self) -> Option<Rc<Vec<u8>>>` (method, since 0.3.2): Bytes. (the original getBlob. None before it is fully read)
  - returns Option<Rc<Vec<u8>>>: Loaded bytes. None before a request, while loading, or on failure.
