@@ -17,7 +17,7 @@ use crate::{
1717 utils:: {
1818 headers:: NatsrpyHeadermapExt ,
1919 natsrpy_future,
20- py_types:: { SendableValue , TimeValue , ToPyDate } ,
20+ py_types:: { TimeValue , ToPyDate } ,
2121 streamer:: Streamer ,
2222 } ,
2323} ;
@@ -253,7 +253,7 @@ impl ObjectStore {
253253 & self ,
254254 py : Python < ' py > ,
255255 name : String ,
256- value : SendableValue ,
256+ value : Vec < u8 > ,
257257 chunk_size : Option < usize > ,
258258 description : Option < String > ,
259259 headers : Option < Bound < ' py , PyDict > > ,
@@ -269,19 +269,45 @@ impl ObjectStore {
269269 headers,
270270 } ;
271271 natsrpy_future ( py, async move {
272- match value {
273- SendableValue :: Bytes ( data) => {
274- let mut reader = tokio:: io:: BufReader :: new ( & * data) ;
275- ctx_guard. read ( ) . await . put ( meta, & mut reader) . await ?;
276- }
277- SendableValue :: String ( filename) => {
278- let mut reader = tokio:: io:: BufReader :: with_capacity (
279- chunk_size. unwrap_or ( 200 * 1024 ) ,
280- tokio:: fs:: File :: open ( filename) . await ?,
281- ) ;
282- ctx_guard. read ( ) . await . put ( meta, & mut reader) . await ?;
283- }
284- }
272+ let mut reader = tokio:: io:: BufReader :: new ( value. as_slice ( ) ) ;
273+ ctx_guard. read ( ) . await . put ( meta, & mut reader) . await ?;
274+ Ok ( ( ) )
275+ } )
276+ }
277+
278+ #[ pyo3( signature=(
279+ name,
280+ path,
281+ chunk_size=None ,
282+ description=None ,
283+ headers=None ,
284+ metadata=None ,
285+ ) ) ]
286+ pub fn put_file < ' py > (
287+ & self ,
288+ py : Python < ' py > ,
289+ name : String ,
290+ path : std:: path:: PathBuf ,
291+ chunk_size : Option < usize > ,
292+ description : Option < String > ,
293+ headers : Option < Bound < ' py , PyDict > > ,
294+ metadata : Option < HashMap < String , String > > ,
295+ ) -> NatsrpyResult < Bound < ' py , PyAny > > {
296+ let ctx_guard = self . object_store . clone ( ) ;
297+ let headers = headers. map ( |val| HeaderMap :: from_pydict ( val) ) . transpose ( ) ?;
298+ let meta = async_nats:: jetstream:: object_store:: ObjectMetadata {
299+ name,
300+ chunk_size,
301+ description,
302+ metadata : metadata. unwrap_or_default ( ) ,
303+ headers,
304+ } ;
305+ natsrpy_future ( py, async move {
306+ let mut reader = tokio:: io:: BufReader :: with_capacity (
307+ chunk_size. unwrap_or ( 200 * 1024 ) ,
308+ tokio:: fs:: File :: open ( path) . await ?,
309+ ) ;
310+ ctx_guard. read ( ) . await . put ( meta, & mut reader) . await ?;
285311 Ok ( ( ) )
286312 } )
287313 }
0 commit comments