Crates.io | qiniu-etag |
lib.rs | qiniu-etag |
version | 0.2.4 |
source | src |
created_at | 2022-04-07 06:22:53.960401 |
updated_at | 2023-12-26 07:14:00.01753 |
description | Qiniu Etag calculation SDK for Rust |
homepage | https://www.qiniu.com |
repository | https://github.com/qiniu/rust-sdk.git |
max_upload_size | |
id | 563478 |
size | 33,644 |
负责根据输入的数据计算七牛 Etag,适配 V1 和 V2 版本,同时提供阻塞接口和异步接口(异步接口需要启用 async
功能)
七牛 Etag 文档:https://developer.qiniu.com/kodo/1231/appendix
[dependencies]
qiniu-etag = "0.2.1"
[dependencies]
qiniu-etag = { version = "0.2.1", features = ["async"] }
use qiniu_etag::{EtagV1, prelude::*};
let mut etag_v1 = EtagV1::new();
etag_v1.update(b"etag");
assert_eq!(etag_v1.finalize_fixed().as_slice(), b"FpLiADEaVoALPkdb8tJEJyRTXoe_");
use std::io::{copy, Cursor};
use qiniu_etag::{EtagV1, prelude::*};
let mut etag_v1 = EtagV1::new();
copy(&mut Cursor::new(b"etag"), &mut etag_v1)?;
assert_eq!(etag_v1.finalize_fixed().as_slice(), b"FpLiADEaVoALPkdb8tJEJyRTXoe_");
use qiniu_etag::{EtagV2, prelude::*};
let mut etag_v2 = EtagV2::new();
etag_v2.update(b"hello");
etag_v2.update(b"world");
assert_eq!(etag_v2.finalize_fixed().as_slice(), b"ns56DcSIfBFUENXjdhsJTIvl3Rcu");
与 V1 不同的是,Etag V2 要求传入数据的分块方式
use qiniu_etag::etag_with_parts;
use std::io::Cursor;
assert_eq!(
etag_with_parts(
&mut Cursor::new(data_of_size(9 << 20)),
&[1 << 22, 1 << 22, 1 << 20]
)?,
"ljgVjMtyMsOgIySv79U8Qz4TrUO4",
);
use futures::io::{copy, Cursor};
use qiniu_etag::{EtagV1, prelude::*};
let mut etag_v1 = EtagV1::new();
copy(&mut Cursor::new(b"etag"), &mut etag_v1).await?;
assert_eq!(etag_v1.finalize_fixed().as_slice(), b"FpLiADEaVoALPkdb8tJEJyRTXoe_");
use qiniu_etag::async_etag_of;
use futures::io::Cursor;
assert_eq!(
async_etag_of(
&mut Cursor::new(data_of_size(9 << 20)),
&[1 << 22, 1 << 22, 1 << 20]
).await?,
"ljgVjMtyMsOgIySv79U8Qz4TrUO4",
);
1.70.0
This project is licensed under the MIT license.