@@ -153,7 +153,8 @@ pub struct PutOptionsBuilder<'bucket> {
153
153
pub ( crate ) value : Data ,
154
154
pub ( crate ) http_metadata : Option < HttpMetadata > ,
155
155
pub ( crate ) custom_metadata : Option < HashMap < String , String > > ,
156
- pub ( crate ) md5 : Option < Vec < u8 > > ,
156
+ pub ( crate ) checksum : Option < Vec < u8 > > ,
157
+ pub ( crate ) checksum_algorithm : String ,
157
158
}
158
159
159
160
impl < ' bucket > PutOptionsBuilder < ' bucket > {
@@ -169,12 +170,37 @@ impl<'bucket> PutOptionsBuilder<'bucket> {
169
170
self
170
171
}
171
172
172
- /// A md5 hash to use to check the received object’s integrity.
173
- pub fn md5 ( mut self , bytes : impl Into < Vec < u8 > > ) -> Self {
174
- self . md5 = Some ( bytes . into ( ) ) ;
173
+ fn checksum_set ( mut self , algorithm : & str , checksum : impl Into < Vec < u8 > > ) -> Self {
174
+ self . checksum_algorithm = algorithm . into ( ) ;
175
+ self . checksum = Some ( checksum . into ( ) ) ;
175
176
self
176
177
}
177
178
179
+ /// A md5 hash to use to check the received object’s integrity.
180
+ pub fn md5 ( self , bytes : impl Into < Vec < u8 > > ) -> Self {
181
+ self . checksum_set ( "md5" , bytes)
182
+ }
183
+
184
+ /// A sha1 hash to use to check the received object’s integrity.
185
+ pub fn sha1 ( self , bytes : impl Into < Vec < u8 > > ) -> Self {
186
+ self . checksum_set ( "sha1" , bytes)
187
+ }
188
+
189
+ /// A sha256 hash to use to check the received object’s integrity.
190
+ pub fn sha256 ( self , bytes : impl Into < Vec < u8 > > ) -> Self {
191
+ self . checksum_set ( "sha256" , bytes)
192
+ }
193
+
194
+ /// A sha384 hash to use to check the received object’s integrity.
195
+ pub fn sha384 ( self , bytes : impl Into < Vec < u8 > > ) -> Self {
196
+ self . checksum_set ( "sha384" , bytes)
197
+ }
198
+
199
+ /// A sha512 hash to use to check the received object’s integrity.
200
+ pub fn sha512 ( self , bytes : impl Into < Vec < u8 > > ) -> Self {
201
+ self . checksum_set ( "sha512" , bytes)
202
+ }
203
+
178
204
/// Executes the PUT operation on the R2 bucket.
179
205
pub async fn execute ( self ) -> Result < Object > {
180
206
let value: JsValue = self . value . into ( ) ;
@@ -195,11 +221,11 @@ impl<'bucket> PutOptionsBuilder<'bucket> {
195
221
}
196
222
None => JsValue :: UNDEFINED ,
197
223
} ,
198
- "md5" => self . md5 . map( |bytes| {
224
+ self . checksum_algorithm => self . checksum . map( |bytes| {
199
225
let arr = Uint8Array :: new_with_length( bytes. len( ) as _) ;
200
226
arr. copy_from( & bytes) ;
201
227
arr. buffer( )
202
- } )
228
+ } ) ,
203
229
}
204
230
. into ( ) ,
205
231
) ;
0 commit comments