# resource/bunchasset (vanilla-engine 0.4.0)

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

묶음 애셋. (원본 resource/bunchasset.js 의 BunchAsset)
- 원본은 BlobAsset 을 상속하고 애셋 타입만 bunch 로 바꾼 뼈대다. 읽기는 BlobAsset 과 같다. (묶음을 푸는 일은 아직 없다)
- 러스트 판은 상속 대신 같은 함수를 가진 구조체이고, 애셋 타입이 AssetType::Bunch 다.

## BunchAsset (struct) (Default, Asset)

묶음 애셋.
- 읽기와 꺼내기는 BlobAsset 과 같고 애셋 타입만 bunch 다.

예제: 가진 바이트로 읽고 애셋 타입 보기

```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): 생성. (애셋 타입 bunch)
  - returns BunchAsset: 요청 전의 빈 묶음 애셋.
- `pub fn load(&mut self, engine: &Engine, asset_path: &str) -> AssetLoadHandle` (method, since 0.3.2): 읽기 요청. (원본 load = BlobAsset.load, await 할 수 있는 읽기 손잡이를 돌려준다)
  - 이미 요청했으면 다시 하지 않고 처음 손잡이를 돌려준다.
  - `engine` &Engine: 바이트를 부탁할 엔진.
  - `asset_path` &str: 애셋 경로. (데스크탑은 애셋 폴더 기준, 웹은 asset_base_url 기준, data: 주소도 된다)
  - returns AssetLoadHandle: 읽기 손잡이. (데스크탑은 그 자리에서 읽혀 끝나 있다. 못 읽으면 실패로 끝난다)
- `pub fn load_from_bytes(&mut self, asset_path: &str, bytes: Vec<u8>)` (method, since 0.3.2): 이미 가진 바이트로 읽기.
  - 이미 요청한 손잡이가 있어도 새 손잡이로 바꾼다.
  - `asset_path` &str: 적어 둘 경로.
  - `bytes` Vec<u8>: 애셋 바이트.
- `pub fn unload(&mut self)` (method, since 0.3.2): 내리기.
- `pub fn get_blob(&self) -> Option<Rc<Vec<u8>>>` (method, since 0.3.2): 바이트. (원본 getBlob. 다 읽히기 전이면 None)
  - returns Option<Rc<Vec<u8>>>: 읽은 바이트. 요청 전이거나 읽는 중이거나 실패했으면 None.
