@@ -4,8 +4,10 @@ use async_compression::tokio::write::ZstdEncoder;
44use tokio:: io;
55
66use crate :: {
7- encode:: DbnEncodable , record_ref:: RecordRef , Error , Metadata , Result , SymbolMapping ,
8- DBN_VERSION , NULL_LIMIT , NULL_RECORD_COUNT , NULL_SCHEMA , NULL_STYPE , UNDEF_TIMESTAMP ,
7+ encode:: { async_zstd_encoder, DbnEncodable } ,
8+ record_ref:: RecordRef ,
9+ Error , Metadata , Result , SymbolMapping , DBN_VERSION , NULL_LIMIT , NULL_RECORD_COUNT ,
10+ NULL_SCHEMA , NULL_STYPE , UNDEF_TIMESTAMP ,
911} ;
1012
1113/// An async encoder for DBN streams.
8486 pub async fn flush ( & mut self ) -> Result < ( ) > {
8587 self . record_encoder . flush ( ) . await
8688 }
89+
90+ /// Initiates or attempts to shut down the inner writer.
91+ ///
92+ /// # Errors
93+ /// This function returns an error if the shut down did not complete successfully.
94+ pub async fn shutdown ( self ) -> Result < ( ) > {
95+ self . record_encoder . shutdown ( ) . await
96+ }
8797}
8898
8999impl < W > Encoder < ZstdEncoder < W > >
@@ -103,7 +113,7 @@ where
103113 /// metadata may have been partially written, but future calls will begin writing
104114 /// the encoded metadata from the beginning.
105115 pub async fn with_zstd ( writer : W , metadata : & Metadata ) -> Result < Self > {
106- Self :: new ( ZstdEncoder :: new ( writer) , metadata) . await
116+ Self :: new ( async_zstd_encoder ( writer) , metadata) . await
107117 }
108118}
109119
@@ -171,6 +181,17 @@ where
171181 . map_err ( |e| Error :: io ( e, "flushing output" . to_owned ( ) ) )
172182 }
173183
184+ /// Initiates or attempts to shut down the inner writer.
185+ ///
186+ /// # Errors
187+ /// This function returns an error if the shut down did not complete successfully.
188+ pub async fn shutdown ( mut self ) -> Result < ( ) > {
189+ self . writer
190+ . shutdown ( )
191+ . await
192+ . map_err ( |e| Error :: io ( e, "shutting down" . to_owned ( ) ) )
193+ }
194+
174195 /// Returns a reference to the underlying writer.
175196 pub fn get_ref ( & self ) -> & W {
176197 & self . writer
@@ -291,11 +312,38 @@ where
291312 Ok ( ( ) )
292313 }
293314
315+ /// Returns a reference to the underlying writer.
316+ pub fn get_ref ( & self ) -> & W {
317+ & self . writer
318+ }
319+
294320 /// Returns a mutable reference to the underlying writer.
295321 pub fn get_mut ( & mut self ) -> & mut W {
296322 & mut self . writer
297323 }
298324
325+ /// Flushes any buffered content to the true output.
326+ ///
327+ /// # Errors
328+ /// This function returns an error if it's unable to flush the underlying writer.
329+ pub async fn flush ( & mut self ) -> Result < ( ) > {
330+ self . writer
331+ . flush ( )
332+ . await
333+ . map_err ( |e| Error :: io ( e, "flushing output" . to_owned ( ) ) )
334+ }
335+
336+ /// Initiates or attempts to shut down the inner writer.
337+ ///
338+ /// # Errors
339+ /// This function returns an error if the shut down did not complete successfully.
340+ pub async fn shutdown ( mut self ) -> Result < ( ) > {
341+ self . writer
342+ . shutdown ( )
343+ . await
344+ . map_err ( |e| Error :: io ( e, "shutting down" . to_owned ( ) ) )
345+ }
346+
299347 /// Consumes the encoder returning the original writer.
300348 pub fn into_inner ( self ) -> W {
301349 self . writer
@@ -430,7 +478,7 @@ where
430478 /// Creates a new [`MetadataEncoder`] that will Zstandard compress the DBN data
431479 /// written to `writer`.
432480 pub fn with_zstd ( writer : W ) -> Self {
433- Self :: new ( ZstdEncoder :: new ( writer) )
481+ Self :: new ( async_zstd_encoder ( writer) )
434482 }
435483}
436484
0 commit comments