vanilladocs
vanillapunch.com
API / resource/blobasset

resource/blobasset

바이너리 애셋. (원본 resource/blobasset.js)

  • 원본은 fetch 로 받은 Blob 을 든다. 러스트 판은 바이트를 그대로 든다.

Binary asset. (the original resource/blobasset.js)

  • The original holds the Blob received with fetch. The Rust version holds the bytes as is.

BlobAssetstruct traits Default, Asset

짝Counterpart: vanilla.js BlobAsset소스source

바이너리 애셋.

  • 받은 바이트를 풀지 않고 그대로 든다. (애셋 타입 blob)

Binary asset.

  • Holds the received bytes as is without decoding. (asset type blob)
예제Example가진 바이트로 읽고 꺼내기Read with bytes in hand and take them out
use vanilla::{Asset, BlobAsset};

let mut blob_asset = BlobAsset::new();
assert!(blob_asset.get_blob().is_none());
blob_asset.load_from_bytes("data.bin", vec![1, 2, 3]);
assert!(blob_asset.is_loaded());
assert_eq!(blob_asset.get_blob().expect("bytes").as_slice(), &[1, 2, 3]);
blob_asset.unload();
assert!(!blob_asset.is_loaded());
생성자constructorpub fn new() -> BlobAsset#0.3.2 부터since 0.3.2소스source

생성.

Constructor.

반환ReturnsBlobAsset 요청 전의 빈 바이너리 애셋.Empty binary asset before a request.

짝Counterpart: vanilla.js BlobAsset.constructor

메서드methodpub fn load(&mut self, engine: &Engine, asset_path: &str) -> AssetLoadHandle#0.3.2 부터since 0.3.2소스source

읽기 요청. (원본 load, await 할 수 있는 읽기 손잡이를 돌려준다)

  • 이미 요청했으면 다시 하지 않고 처음 손잡이를 돌려준다.

Requests a read. (the original 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_base_url 기준, data: 주소도 된다)Asset path. (relative to the asset folder on desktop, to asset_base_url on the web; data: URLs also work)

반환ReturnsAssetLoadHandle 읽기 손잡이. (데스크탑은 그 자리에서 읽혀 끝나 있다. 못 읽으면 실패로 끝난다)Load handle. (on desktop it is read on the spot and already finished. Finishes in failure if it cannot be read)

짝Counterpart: vanilla.js BlobAsset.load

예제Exampledata: 주소를 데스크탑에서 그 자리에서 읽기Read a data: URL on the spot on desktop
use vanilla::{BlobAsset, Engine, EngineConfiguration};

let engine = Engine::new(EngineConfiguration::new());
let mut blob_asset = BlobAsset::new();
let load_handle = blob_asset.load(&engine, "data:,abc");
assert!(load_handle.is_loaded());
assert_eq!(blob_asset.get_blob().expect("bytes").as_slice(), b"abc");
메서드methodpub fn load_from_bytes(&mut self, asset_path: &str, bytes: Vec<u8>)#0.3.2 부터since 0.3.2소스source

이미 가진 바이트로 읽기.

  • 이미 요청한 손잡이가 있어도 새 손잡이로 바꾼다.

Reads from bytes already in hand.

  • Replaces it with a new handle even if a requested handle exists.
asset_path&str
적어 둘 경로.Path to record.
bytesVec<u8>
애셋 바이트.Asset bytes.

짝Counterpart: vanilla.js BlobAsset.loadFromBytes

메서드methodpub fn unload(&mut self)#0.3.2 부터since 0.3.2소스source

내리기.

Unloads.

짝Counterpart: vanilla.js Asset.unload

메서드methodpub fn get_blob(&self) -> Option<Rc<Vec<u8>>>#0.3.2 부터since 0.3.2소스source

바이트. (원본 getBlob. 다 읽히기 전이면 None)

Bytes. (the original getBlob. None before it is fully read)

반환ReturnsOption<Rc<Vec<u8>>> 읽은 바이트. 요청 전이거나 읽는 중이거나 실패했으면 None.Loaded bytes. None before a request, while loading, or on failure.

짝Counterpart: vanilla.js BlobAsset.getBlob