pyarrow.OSFile#
- classpyarrow.OSFile#
Bases:
NativeFile
A stream backed by a regular file descriptor.
Examples
Create a new file to write to:
>>>importpyarrowaspa>>>withpa.OSFile('example_osfile.arrow',mode='w')asf:...f.writable()...f.write(b'OSFile')...f.seekable()...True6False
Open the file to read:
>>>withpa.OSFile('example_osfile.arrow',mode='r')asf:...f.mode...f.read()...'rb'b'OSFile'
Open the file to append:
>>>withpa.OSFile('example_osfile.arrow',mode='ab')asf:...f.mode...f.write(b' is super!')...'ab'10>>>withpa.OSFile('example_osfile.arrow')asf:...f.read()...b'OSFile is super!'
Inspect created OSFile:
>>>pa.OSFile('example_osfile.arrow')<pyarrow.OSFile closed=False own_file=False is_seekable=True is_writable=False is_readable=True>
- __init__(*args,**kwargs)#
Methods
__init__
(*args, **kwargs)close
(self)download
(self, stream_or_path[, buffer_size])Read this file completely to a local path or destination stream.
fileno
(self)flush
(self)Flush the stream, if applicable.
get_stream
(self, file_offset, nbytes)Return an input stream that reads a file segment independent of the state of the file.
isatty
(self)metadata
(self)Return file metadata
read
(self[, nbytes])Read and return up to n bytes.
read1
(self[, nbytes])Read and return up to n bytes.
read_at
(self, nbytes, offset)Read indicated number of bytes at offset from the file
read_buffer
(self[, nbytes])Read from buffer.
readable
(self)readall
(self)readinto
(self, b)Read into the supplied buffer
readline
(self[, size])NOT IMPLEMENTED.
readlines
(self[, hint])NOT IMPLEMENTED.
seek
(self, int64_t position, int whence=0)Change current file stream position
seekable
(self)size
(self)Return file size
tell
(self)Return current stream position
truncate
(self)NOT IMPLEMENTED
upload
(self, stream[, buffer_size])Write from a source stream to this file.
writable
(self)write
(self, data)Write data to the file.
writelines
(self, lines)Write lines to the file.
Attributes
- close(self)#
- closed#
- download(self,stream_or_path,buffer_size=None)#
Read this file completely to a local path or destination stream.
This method first seeks to the beginning of the file.
- fileno(self)#
- flush(self)#
Flush the stream, if applicable.
An error is raised if stream is not writable.
- get_stream(self,file_offset,nbytes)#
Return an input stream that reads a file segment independent of thestate of the file.
Allows reading portions of a random access file as an input streamwithout interfering with each other.
- Parameters:
- Returns:
- stream
NativeFile
- stream
- isatty(self)#
- metadata(self)#
Return file metadata
- mode#
The file mode. Currently instances of NativeFile may support:
rb: binary read
wb: binary write
rb+: binary read and write
ab: binary append
- read(self,nbytes=None)#
Read and return up to n bytes.
Ifnbytes is None, then the entire remaining file contents are read.
- read1(self,nbytes=None)#
Read and return up to n bytes.
Unlike read(), ifnbytes is None then a chunk is read, not theentire file.
- read_at(self,nbytes,offset)#
Read indicated number of bytes at offset from the file
- read_buffer(self,nbytes=None)#
Read from buffer.
- Parameters:
- nbytes
int
, optional maximum number of bytes read
- nbytes
- readable(self)#
- readall(self)#
- readinto(self,b)#
Read into the supplied buffer
- Parameters:
- bbuffer-like object
A writable buffer object (such as a bytearray).
- Returns:
- written
int
number of bytes written
- written
- readline(self,size=None)#
NOT IMPLEMENTED. Read and return a line of bytes from the file.
If size is specified, read at most size bytes.
Line terminator is always b”n”.
- Parameters:
- size
int
maximum number of bytes read
- size
- readlines(self,hint=None)#
NOT IMPLEMENTED. Read lines of the file
- Parameters:
- hint
int
maximum number of bytes read until we stop
- hint
- seek(self,int64_tposition,intwhence=0)#
Change current file stream position
- Parameters:
- Returns:
int
The new absolute stream position.
Notes
Values of whence:* 0 – start of stream (the default); offset should be zero or positive* 1 – current stream position; offset may be negative* 2 – end of stream; offset is usually negative
- seekable(self)#
- size(self)#
Return file size
- tell(self)#
Return current stream position
- truncate(self)#
NOT IMPLEMENTED
- upload(self,stream,buffer_size=None)#
Write from a source stream to this file.
- Parameters:
- streamfile-like object
Source stream to pipe to this file.
- buffer_size
int
, optional The buffer size to use for data transfers.
- writable(self)#