pub fn read_file_metadata<R: Read + Seek>(reader: &mut R) -> Result<FileMetadata> {
    // check if header and footer contain correct magic bytes
    let mut magic_buffer: [u8; 6] = [0; 6];
    reader.read_exact(&mut magic_buffer)?;
    if magic_buffer != ARROW_MAGIC {
        return Err(ArrowError::OutOfSpec(
            "Arrow file does not contain correct header".to_string(),
        ));
    }
    reader.seek(SeekFrom::End(-6))?;
    reader.read_exact(&mut magic_buffer)?;
    if magic_buffer != ARROW_MAGIC {
        return Err(ArrowError::OutOfSpec(
            "Arrow file does not contain correct footer".to_string(),
        ));
    }
    // read footer length
    let mut footer_size: [u8; 4] = [0; 4];
    reader.seek(SeekFrom::End(-10))?;
    reader.read_exact(&mut footer_size)?;
    let footer_len = i32::from_le_bytes(footer_size);

    // read footer
    let mut footer_data = vec![0; footer_len as usize];
    reader.seek(SeekFrom::End(-10 - footer_len as i64))?;
    reader.read_exact(&mut footer_data)?;

    let footer = arrow_format::ipc::FooterRef::read_as_root(&footer_data)
        .map_err(|err| ArrowError::OutOfSpec(format!("Unable to get root as footer: {:?}", err)))?;

    let blocks = footer.record_batches()?.ok_or_else(|| {
        ArrowError::OutOfSpec("Unable to get record batches from footer".to_string())
    })?;

    let ipc_schema = footer
        .schema()?
        .ok_or_else(|| ArrowError::OutOfSpec("Unable to get the schema from footer".to_string()))?;
    let (schema, ipc_schema) = fb_to_schema(ipc_schema)?;

    let dictionary_blocks = footer.dictionaries()?;

    let dictionaries = if let Some(blocks) = dictionary_blocks {
        read_dictionaries(reader, &schema.fields, &ipc_schema, blocks)?
    } else {
        Default::default()
    };

    Ok(FileMetadata {
        schema,
        ipc_schema,
        blocks: blocks
            .iter()
            .map(|block| Ok(block.try_into()?))
            .collect::<Result<Vec<_>>>()?,
        dictionaries,
    })
}
/// Read the IPC file's metadata
Read the IPC file's metadata
Read the IPC file ' s metadata
pub fn read_file_metadata<R: Read + Seek>(reader: &mut R) -> Result<FileMetadata> {
    // check if header and footer contain correct magic bytes
    let mut magic_buffer: [u8; 6] = [0; 6];
    reader.read_exact(&mut magic_buffer)?;
    if magic_buffer != ARROW_MAGIC {
        return Err(ArrowError::OutOfSpec(
            "Arrow file does not contain correct header".to_string(),
        ));
    }
    reader.seek(SeekFrom::End(-6))?;
    reader.read_exact(&mut magic_buffer)?;
    if magic_buffer != ARROW_MAGIC {
        return Err(ArrowError::OutOfSpec(
            "Arrow file does not contain correct footer".to_string(),
        ));
    }
    // read footer length
    let mut footer_size: [u8; 4] = [0; 4];
    reader.seek(SeekFrom::End(-10))?;
    reader.read_exact(&mut footer_size)?;
    let footer_len = i32::from_le_bytes(footer_size);
    // read footer
    let mut footer_data = vec![0; footer_len as usize];
    reader.seek(SeekFrom::End(-10 - footer_len as i64))?;
    reader.read_exact(&mut footer_data)?;
    let footer = arrow_format::ipc::FooterRef::read_as_root(&footer_data)
        .map_err(|err| ArrowError::OutOfSpec(format!("Unable to get root as footer: {:?}", err)))?;
    let blocks = footer.record_batches()?.ok_or_else(|| {
        ArrowError::OutOfSpec("Unable to get record batches from footer".to_string())
    })?;
    let ipc_schema = footer
        .schema()?
        .ok_or_else(|| ArrowError::OutOfSpec("Unable to get the schema from footer".to_string()))?;
    let (schema, ipc_schema) = fb_to_schema(ipc_schema)?;
    let dictionary_blocks = footer.dictionaries()?;
    let dictionaries = if let Some(blocks) = dictionary_blocks {
        read_dictionaries(reader, &schema.fields, &ipc_schema, blocks)?
    } else {
        Default::default()
    };
    Ok(FileMetadata {
        schema,
        ipc_schema,
        blocks: blocks
            .iter()
            .map(|block| Ok(block.try_into()?))
            .collect::<Result<Vec<_>>>()?,
        dictionaries,
    })
}
pub fn read_file_metadata < R : Read + Seek > ( reader : & mut R ) -> Result < FileMetadata > { // check if header and footer contain correct magic bytes let mut magic_buffer : [ u8 ; 6 ] = [ 0 ; 6 ] ; reader . read_exact ( & mut magic_buffer ) ? ; if magic_buffer != ARROW_MAGIC { return Err ( ArrowError :: OutOfSpec ( " " . to_string ( ) , ) ) ; } reader . seek ( SeekFrom :: End ( - 6 ) ) ? ; reader . read_exact ( & mut magic_buffer ) ? ; if magic_buffer != ARROW_MAGIC { return Err ( ArrowError :: OutOfSpec ( " " . to_string ( ) , ) ) ; } // read footer length let mut footer_size : [ u8 ; 4 ] = [ 0 ; 4 ] ; reader . seek ( SeekFrom :: End ( - 10 ) ) ? ; reader . read_exact ( & mut footer_size ) ? ; let footer_len = i32 :: from_le_bytes ( footer_size ) ; // read footer let mut footer_data = vec ! [ 0 footer_len as usize ] ; reader . seek ( SeekFrom :: End ( - 10 - footer_len as i64 ) ) ? ; reader . read_exact ( & mut footer_data ) ? ; let footer = arrow_format :: ipc :: FooterRef :: read_as_root ( & footer_data ) . map_err ( | err | ArrowError :: OutOfSpec ( format ! ( " " err ) ) ) ? ; let blocks = footer . record_batches ( ) ? . ok_or_else ( | | { ArrowError :: OutOfSpec ( " " . to_string ( ) ) } ) ? ; let ipc_schema = footer . schema ( ) ? . ok_or_else ( | | ArrowError :: OutOfSpec ( " " . to_string ( ) ) ) ? ; let ( schema , ipc_schema ) = fb_to_schema ( ipc_schema ) ? ; let dictionary_blocks = footer . dictionaries ( ) ? ; let dictionaries = if let Some ( blocks ) = dictionary_blocks { read_dictionaries ( reader , & schema . fields , & ipc_schema , blocks ) ? } else { Default :: default ( ) } ; Ok ( FileMetadata { schema , ipc_schema , blocks : blocks . iter ( ) . map ( | block | Ok ( block . try_into ( ) ? ) ) . collect :: < Result < Vec < _ > > > ( ) ? , dictionaries , } ) }
Read the IPC file's metadata
Read the IPC file ' s metadata
reader
&mut R
reader
&mut R