Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
remove buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
yjshen committed Sep 21, 2021
1 parent c317a82 commit b5a9b09
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions examples/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ fn write_ipc<W: Write + Seek>(writer: W, array: impl Array + 'static) -> Result<

let batch = RecordBatch::try_new(Arc::new(schema), vec![Arc::new(array)])?;

writer.write(&batch);
writer.write(&batch)?;

writer.into_inner()
Ok(writer.into_inner())
}

fn read_ipc(reader: &[u8]) -> Result<RecordBatch> {
Expand Down
11 changes: 5 additions & 6 deletions src/io/ipc/write/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//! The `FileWriter` and `StreamWriter` have similar interfaces,
//! however the `FileWriter` expects a reader that supports `Seek`ing
use std::io::{Error, Write, BufWriter};
use std::io::Write;

use super::super::ARROW_MAGIC;
use super::{
Expand All @@ -39,7 +39,7 @@ use crate::record_batch::RecordBatch;

pub struct FileWriter<W: Write> {
/// The object to write to
writer: BufWriter<W>,
writer: W,
/// IPC write options
write_options: IpcWriteOptions,
/// A reference to the schema, used in validating record batches
Expand All @@ -65,11 +65,10 @@ impl<W: Write> FileWriter<W> {

/// Try create a new writer with IpcWriteOptions
pub fn try_new_with_options(
writer: W,
mut writer: W,
schema: &Schema,
write_options: IpcWriteOptions,
) -> Result<Self> {
let mut writer = BufWriter::new(writer);
// write magic to header
writer.write_all(&ARROW_MAGIC[..])?;
// create an 8-byte boundary after the header
Expand All @@ -92,8 +91,8 @@ impl<W: Write> FileWriter<W> {
})
}

pub fn into_inner(self) -> Result<W> {
self.writer.into_inner().map_err(|e| Error::from(e).into())
pub fn into_inner(self) -> W {
self.writer
}

/// Write a record batch to the file
Expand Down
4 changes: 2 additions & 2 deletions tests/it/io/ipc/write/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn round_trip(batch: RecordBatch) -> Result<()> {
let mut writer = FileWriter::try_new_with_options(result, batch.schema(), options)?;
writer.write(&batch)?;
writer.finish()?;
writer.into_inner()?
writer.into_inner()
};
let mut reader = Cursor::new(written_result);
let metadata = read_file_metadata(&mut reader)?;
Expand Down Expand Up @@ -49,7 +49,7 @@ fn test_file(version: &str, file_name: &str) -> Result<()> {
writer.write(&batch)?;
}
writer.finish()?;
writer.into_inner()?
writer.into_inner()
};
let mut reader = Cursor::new(written_result);
let metadata = read_file_metadata(&mut reader)?;
Expand Down

0 comments on commit b5a9b09

Please sign in to comment.