airfs.storage.azure_blob

Microsoft Azure Storage Blob

New in version 1.3.0.

Mount

An Azure storage account can be mounted using the airfs mount function.

storage_parameters await arguments to pass to the azure.storage.blob.baseblobservice.BaseBlobService class from azure-storage-blob Python library.

This example shows the mount of Azure Storage Blob with the minimal configuration:

import airfs

# Mount Azure Storage Blob manually (Minimal configuration)
airfs.mount(storage='azure_blob', storage_parameters=dict(
        account_name='my_account_name',
        account_key='my_account_key'
    )
)

# Call of airfs on an Azure Storage blob.
with airfs.open(
        'https://my_account.blob.core.windows.net/my_container/my_blob',
        'rt'
        ) as file:
    text = file.read()

If using multiple Azure storage accounts simultaneously, the sas_token argument of the BaseBlobService class is required to allow blob and files copies across different accounts.

It is possible to mount Azure Storage Blob and Azure Storage File with a single airfs.mount call by using storage='azure' instead of storage='azure_blob'.

Limitation

Only one configuration per Azure Storage account can be mounted simultaneously.

Azure blob type selection

It is possible to select the blob type for new files created using the blob_type argument.

Possible blob types are BlockBlob, AppendBlob & PageBlob.

The default blob type can be set when mounting the storage (if not specified, the BlockBlob type is used by default):

import airfs

airfs.mount(
    storage='azure_blob',
    storage_parameters=dict(
        account_name='my_account_name',
        account_key='my_account_key',
        blob_type='PageBlob',  # Using PageBlob by default for new files
    )
)

It can also be selected for a specific file when opening it in write mode:

# Open a new file in write mode as PageBlob
with airfs.open(
        'https://my_account.blob.core.windows.net/my_container/my_blob',
        'wb',
        blob_type='PageBlob'
        ) as file:
    file.write(b'0')

Page blobs specific features

The page blob supports the following specific features.

Pre-allocating pages

When flushing a page blob out of its current size, airfs first resize the blob to allow the flush of the new data.

In case of multiple flushes on a raw IO or when using a buffered IO, this is done with extra requests to the Azure server. If The size to write is known before opening the file, it is possible to avoid these extra requests by to preallocate the required size in only one initial request.

The content_length argument allow pre-allocating a Page blob to a defined size when opening it in write mode:

# Open a new page blob and preallocate it with 1024 bytes.
with airfs.open(
        'https://my_account.blob.core.windows.net/my_container/my_blob',
        'wb',
        blob_type='PageBlob',
        content_length=1024
        ) as file:
    file.write(b'1')

# Append on an existing page blob and pre-resize it to 2048 bytes.
with airfs.open(
        'https://my_account.blob.core.windows.net/my_container/my_blob',
        'ab',
        blob_type='PageBlob',
        content_length=2048
        ) as file:
    file.write(b'1')

The pre-allocation is done with padding of null characters (b'\0').

End page padding handling

By default, airfs tries to handle page blobs like standard files by ignoring trailing page padding of null characters:

  • When opening a file in append mode (Seek to the end of file after ignoring trailing padding of the last page).

  • When reading data (Read until a null character reaches).

  • When using the seek() method with whence=os.SEEK_END (Ignore the trailing padding when determining the end of the file to use as the reference position)

This behaviour can be disabled using the ignore_padding=False argument when opening the page blob.

Files objects classes

Microsoft Azure Blobs Storage.

class airfs.storage.azure_blob.AzureAppendBlobBufferedIO(name, mode='r', buffer_size=None, max_buffers=0, max_workers=None, **kwargs)

Buffered binary Azure Append Blobs Storage Object I/O.

This blob type is not seekable in “write” mode.

close()

Flush the write buffers of the stream if applicable and close the object.

detach()

Disconnect this buffer from its underlying raw stream and return it.

After the raw stream has been detached, the buffer is in an unusable state.

fileno()

Returns underlying file descriptor if one exists.

OSError is raised if the IO object does not use a file descriptor.

flush()

Flush the write buffers of the stream if applicable.

isatty()

Return whether this is an ‘interactive’ stream.

Return False if it can’t be determined.

property mode

The mode.

Returns:

Mode.

Return type:

str

property name

The file name.

Returns:

Name.

Return type:

str

peek(size=-1)

Return bytes from the stream without advancing the position.

Parameters:

size (int) – Number of bytes to read. -1 to read the full stream.

Returns:

bytes read

Return type:

bytes

property raw

The underlying raw stream.

Returns:

Raw stream.

Return type:

ObjectRawIOBase subclass

read(size=-1)

Read the object content.

Read and return up to size bytes, with at most one call to the underlying raw stream.

Use at most one call to the underlying raw stream’s read method.

Parameters:

size (int) – Number of bytes to read. -1 to read the stream until the end.

Returns:

Object content

Return type:

bytes

read1(size=-1)

Read the object content.

Read and return up to size bytes, with at most one call to the underlying raw stream.

Use at most one call to the underlying raw stream’s read method.

Parameters:

size (int) – Number of bytes to read. -1 to read the stream until the end.

Returns:

Object content

Return type:

bytes

readable()

Return True if the stream can be read from.

If False, read() will raise OSError.

Returns:

Supports reading.

Return type:

bool

readinto(b)

Read the object content into a buffer.

Read bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read.

Parameters:

b (bytes-like object) – buffer.

Returns:

number of bytes read

Return type:

int

readinto1(b)

Read the object content into a buffer.

Read bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read.

Use at most one call to the underlying raw stream’s readinto method.

Parameters:

b (bytes-like object) – buffer.

Returns:

number of bytes read

Return type:

int

readline(size=-1, /)

Read and return a line from the stream.

If size is specified, at most size bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

readlines(hint=-1, /)

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

seek(offset, whence=0)

Change the stream position to the given byte offset.

Parameters:
  • offset – Offset is interpreted relative to the position indicated by whence.

  • whence – The default value for whence is SEEK_SET. Values are: SEEK_SET or 0 – Start of the stream (the default); offset should be zero or positive SEEK_CUR or 1 – Current stream position; offset may be negative SEEK_END or 2 – End of the stream; offset is usually negative

Returns:

The new absolute position.

Return type:

int

seekable()

Return True if the stream supports random access.

If False, seek(), tell() and truncate() will raise OSError.

Returns:

Supports random access.

Return type:

bool

tell()

Return the current stream position.

Returns:

Stream position.

Return type:

int

truncate()

Truncate file to size bytes.

File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Returns the new size.

writable()

Return True if the stream supports writing.

If False, write() and truncate() will raise OSError.

Returns:

Supports writing.

Return type:

bool

write(b)

Write into the object.

Write the given bytes-like object, b, to the underlying raw stream, and return the number of bytes written.

Parameters:

b (bytes-like object) – Bytes to write.

Returns:

The number of bytes written.

Return type:

int

writelines(lines, /)

Write a list of lines to stream.

Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end.

class airfs.storage.azure_blob.AzureAppendBlobRawIO(name, mode='r', **kwargs)

Binary Azure Append Blobs Storage Object I/O.

This blob type is not seekable in “write” mode.

close()

Flush the write buffers of the stream if applicable and close the object.

fileno()

Returns underlying file descriptor if one exists.

OSError is raised if the IO object does not use a file descriptor.

flush()

Flush.

Flush the write buffers of the stream if applicable and save the object on the storage.

isatty()

Return whether this is an ‘interactive’ stream.

Return False if it can’t be determined.

property mode

The mode.

Returns:

Mode.

Return type:

str

property name

The file name.

Returns:

Name.

Return type:

str

readable()

Return True if the stream can be read from.

If False, read() will raise OSError.

Returns:

Supports reading.

Return type:

bool

readall()

Read and return all the bytes from the stream until EOF.

Returns:

Object content

Return type:

bytes

readinto(b)

Read the object content into a buffer.

Read bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read.

Parameters:

b (bytes-like object) – buffer.

Returns:

number of bytes read

Return type:

int

readline(size=-1, /)

Read and return a line from the stream.

If size is specified, at most size bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

readlines(hint=-1, /)

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

seek(offset, whence=0)

Change the stream position to the given byte offset.

Parameters:
  • offset (int) – Offset is interpreted relative to the position indicated by whence.

  • whence (int) – The default value for whence is SEEK_SET. Values are: SEEK_SET or 0 – Start of the stream (the default); offset should be zero or positive SEEK_CUR or 1 – Current stream position; offset may be negative SEEK_END or 2 – End of the stream; offset is usually negative

Returns:

The new absolute position.

Return type:

int

seekable()

Return True if the stream supports random access.

If False, seek(), tell() and truncate() will raise OSError.

Returns:

Supports random access.

Return type:

bool

tell()

Return the current stream position.

Returns:

Stream position.

Return type:

int

truncate()

Truncate file to size bytes.

File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Returns the new size.

writable()

Return True if the stream supports writing.

If False, write() and truncate() will raise OSError.

Returns:

Supports writing.

Return type:

bool

write(b)

Write into the object.

Write the given bytes-like object, b, to the underlying raw stream, and return the number of bytes written.

Parameters:

b (bytes-like object) – Bytes to write.

Returns:

The number of bytes written.

Return type:

int

writelines(lines, /)

Write a list of lines to stream.

Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end.

class airfs.storage.azure_blob.AzureBlobBufferedIO(name, mode='r', buffer_size=None, max_buffers=0, max_workers=None, **kwargs)

Buffered binary Azure Blobs Storage Object I/O.

close()

Flush the write buffers of the stream if applicable and close the object.

detach()

Disconnect this buffer from its underlying raw stream and return it.

After the raw stream has been detached, the buffer is in an unusable state.

fileno()

Returns underlying file descriptor if one exists.

OSError is raised if the IO object does not use a file descriptor.

flush()

Flush the write buffers of the stream if applicable.

isatty()

Return whether this is an ‘interactive’ stream.

Return False if it can’t be determined.

property mode

The mode.

Returns:

Mode.

Return type:

str

property name

The file name.

Returns:

Name.

Return type:

str

peek(size=-1)

Return bytes from the stream without advancing the position.

Parameters:

size (int) – Number of bytes to read. -1 to read the full stream.

Returns:

bytes read

Return type:

bytes

property raw

The underlying raw stream.

Returns:

Raw stream.

Return type:

ObjectRawIOBase subclass

read(size=-1)

Read the object content.

Read and return up to size bytes, with at most one call to the underlying raw stream.

Use at most one call to the underlying raw stream’s read method.

Parameters:

size (int) – Number of bytes to read. -1 to read the stream until the end.

Returns:

Object content

Return type:

bytes

read1(size=-1)

Read the object content.

Read and return up to size bytes, with at most one call to the underlying raw stream.

Use at most one call to the underlying raw stream’s read method.

Parameters:

size (int) – Number of bytes to read. -1 to read the stream until the end.

Returns:

Object content

Return type:

bytes

readable()

Return True if the stream can be read from.

If False, read() will raise OSError.

Returns:

Supports reading.

Return type:

bool

readinto(b)

Read the object content into a buffer.

Read bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read.

Parameters:

b (bytes-like object) – buffer.

Returns:

number of bytes read

Return type:

int

readinto1(b)

Read the object content into a buffer.

Read bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read.

Use at most one call to the underlying raw stream’s readinto method.

Parameters:

b (bytes-like object) – buffer.

Returns:

number of bytes read

Return type:

int

readline(size=-1, /)

Read and return a line from the stream.

If size is specified, at most size bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

readlines(hint=-1, /)

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

seek(offset, whence=0)

Change the stream position to the given byte offset.

Parameters:
  • offset – Offset is interpreted relative to the position indicated by whence.

  • whence – The default value for whence is SEEK_SET. Values are: SEEK_SET or 0 – Start of the stream (the default); offset should be zero or positive SEEK_CUR or 1 – Current stream position; offset may be negative SEEK_END or 2 – End of the stream; offset is usually negative

Returns:

The new absolute position.

Return type:

int

seekable()

Return True if the stream supports random access.

If False, seek(), tell() and truncate() will raise OSError.

Returns:

Supports random access.

Return type:

bool

tell()

Return the current stream position.

Returns:

Stream position.

Return type:

int

truncate()

Truncate file to size bytes.

File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Returns the new size.

writable()

Return True if the stream supports writing.

If False, write() and truncate() will raise OSError.

Returns:

Supports writing.

Return type:

bool

write(b)

Write into the object.

Write the given bytes-like object, b, to the underlying raw stream, and return the number of bytes written.

Parameters:

b (bytes-like object) – Bytes to write.

Returns:

The number of bytes written.

Return type:

int

writelines(lines, /)

Write a list of lines to stream.

Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end.

class airfs.storage.azure_blob.AzureBlobRawIO(name, mode='r', **kwargs)

Binary Azure Blobs Storage Object I/O.

close()

Flush the write buffers of the stream if applicable and close the object.

fileno()

Returns underlying file descriptor if one exists.

OSError is raised if the IO object does not use a file descriptor.

flush()

Flush.

Flush the write buffers of the stream if applicable and save the object on the storage.

isatty()

Return whether this is an ‘interactive’ stream.

Return False if it can’t be determined.

property mode

The mode.

Returns:

Mode.

Return type:

str

property name

The file name.

Returns:

Name.

Return type:

str

readable()

Return True if the stream can be read from.

If False, read() will raise OSError.

Returns:

Supports reading.

Return type:

bool

readall()

Read and return all the bytes from the stream until EOF.

Returns:

Object content

Return type:

bytes

readinto(b)

Read the object content into a buffer.

Read bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read.

Parameters:

b (bytes-like object) – buffer.

Returns:

number of bytes read

Return type:

int

readline(size=-1, /)

Read and return a line from the stream.

If size is specified, at most size bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

readlines(hint=-1, /)

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

seek(offset, whence=0)

Change the stream position to the given byte offset.

Parameters:
  • offset (int) – Offset is interpreted relative to the position indicated by whence.

  • whence (int) – The default value for whence is SEEK_SET. Values are: SEEK_SET or 0 – Start of the stream (the default); offset should be zero or positive SEEK_CUR or 1 – Current stream position; offset may be negative SEEK_END or 2 – End of the stream; offset is usually negative

Returns:

The new absolute position.

Return type:

int

seekable()

Return True if the stream supports random access.

If False, seek(), tell() and truncate() will raise OSError.

Returns:

Supports random access.

Return type:

bool

tell()

Return the current stream position.

Returns:

Stream position.

Return type:

int

truncate()

Truncate file to size bytes.

File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Returns the new size.

writable()

Return True if the stream supports writing.

If False, write() and truncate() will raise OSError.

Returns:

Supports writing.

Return type:

bool

write(b)

Write into the object.

Write the given bytes-like object, b, to the underlying raw stream, and return the number of bytes written.

Parameters:

b (bytes-like object) – Bytes to write.

Returns:

The number of bytes written.

Return type:

int

writelines(lines, /)

Write a list of lines to stream.

Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end.

class airfs.storage.azure_blob.AzureBlockBlobBufferedIO(name, mode='r', buffer_size=None, max_buffers=0, max_workers=None, **kwargs)

Buffered binary Azure Block Blobs Storage Object I/O.

close()

Flush the write buffers of the stream if applicable and close the object.

detach()

Disconnect this buffer from its underlying raw stream and return it.

After the raw stream has been detached, the buffer is in an unusable state.

fileno()

Returns underlying file descriptor if one exists.

OSError is raised if the IO object does not use a file descriptor.

flush()

Flush the write buffers of the stream if applicable.

isatty()

Return whether this is an ‘interactive’ stream.

Return False if it can’t be determined.

property mode

The mode.

Returns:

Mode.

Return type:

str

property name

The file name.

Returns:

Name.

Return type:

str

peek(size=-1)

Return bytes from the stream without advancing the position.

Parameters:

size (int) – Number of bytes to read. -1 to read the full stream.

Returns:

bytes read

Return type:

bytes

property raw

The underlying raw stream.

Returns:

Raw stream.

Return type:

ObjectRawIOBase subclass

read(size=-1)

Read the object content.

Read and return up to size bytes, with at most one call to the underlying raw stream.

Use at most one call to the underlying raw stream’s read method.

Parameters:

size (int) – Number of bytes to read. -1 to read the stream until the end.

Returns:

Object content

Return type:

bytes

read1(size=-1)

Read the object content.

Read and return up to size bytes, with at most one call to the underlying raw stream.

Use at most one call to the underlying raw stream’s read method.

Parameters:

size (int) – Number of bytes to read. -1 to read the stream until the end.

Returns:

Object content

Return type:

bytes

readable()

Return True if the stream can be read from.

If False, read() will raise OSError.

Returns:

Supports reading.

Return type:

bool

readinto(b)

Read the object content into a buffer.

Read bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read.

Parameters:

b (bytes-like object) – buffer.

Returns:

number of bytes read

Return type:

int

readinto1(b)

Read the object content into a buffer.

Read bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read.

Use at most one call to the underlying raw stream’s readinto method.

Parameters:

b (bytes-like object) – buffer.

Returns:

number of bytes read

Return type:

int

readline(size=-1, /)

Read and return a line from the stream.

If size is specified, at most size bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

readlines(hint=-1, /)

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

seek(offset, whence=0)

Change the stream position to the given byte offset.

Parameters:
  • offset – Offset is interpreted relative to the position indicated by whence.

  • whence – The default value for whence is SEEK_SET. Values are: SEEK_SET or 0 – Start of the stream (the default); offset should be zero or positive SEEK_CUR or 1 – Current stream position; offset may be negative SEEK_END or 2 – End of the stream; offset is usually negative

Returns:

The new absolute position.

Return type:

int

seekable()

Return True if the stream supports random access.

If False, seek(), tell() and truncate() will raise OSError.

Returns:

Supports random access.

Return type:

bool

tell()

Return the current stream position.

Returns:

Stream position.

Return type:

int

truncate()

Truncate file to size bytes.

File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Returns the new size.

writable()

Return True if the stream supports writing.

If False, write() and truncate() will raise OSError.

Returns:

Supports writing.

Return type:

bool

write(b)

Write into the object.

Write the given bytes-like object, b, to the underlying raw stream, and return the number of bytes written.

Parameters:

b (bytes-like object) – Bytes to write.

Returns:

The number of bytes written.

Return type:

int

writelines(lines, /)

Write a list of lines to stream.

Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end.

class airfs.storage.azure_blob.AzureBlockBlobRawIO(name, mode='r', **kwargs)

Binary Azure BLock Blobs Storage Object I/O.

Parameters:
  • name (path-like object) – URL or path to the file which will be opened.

  • mode (str) – The mode can be ‘r’, ‘w’, ‘a’ for reading (default), writing or appending.

  • storage_parameters (dict) – Azure service keyword arguments. This is generally Azure credentials and configuration. See “azure.storage.blob.baseblobservice.BaseBlobService” for more information.

  • unsecure (bool) – If True, disables TLS/SSL to improve transfer performance. But makes connection unsecure.

close()

Flush the write buffers of the stream if applicable and close the object.

fileno()

Returns underlying file descriptor if one exists.

OSError is raised if the IO object does not use a file descriptor.

flush()

Flush.

Flush the write buffers of the stream if applicable and save the object on the storage.

isatty()

Return whether this is an ‘interactive’ stream.

Return False if it can’t be determined.

property mode

The mode.

Returns:

Mode.

Return type:

str

property name

The file name.

Returns:

Name.

Return type:

str

readable()

Return True if the stream can be read from.

If False, read() will raise OSError.

Returns:

Supports reading.

Return type:

bool

readall()

Read and return all the bytes from the stream until EOF.

Returns:

Object content

Return type:

bytes

readinto(b)

Read the object content into a buffer.

Read bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read.

Parameters:

b (bytes-like object) – buffer.

Returns:

number of bytes read

Return type:

int

readline(size=-1, /)

Read and return a line from the stream.

If size is specified, at most size bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

readlines(hint=-1, /)

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

seek(offset, whence=0)

Change the stream position to the given byte offset.

Parameters:
  • offset (int) – Offset is interpreted relative to the position indicated by whence.

  • whence (int) – The default value for whence is SEEK_SET. Values are: SEEK_SET or 0 – Start of the stream (the default); offset should be zero or positive SEEK_CUR or 1 – Current stream position; offset may be negative SEEK_END or 2 – End of the stream; offset is usually negative

Returns:

The new absolute position.

Return type:

int

seekable()

Return True if the stream supports random access.

If False, seek(), tell() and truncate() will raise OSError.

Returns:

Supports random access.

Return type:

bool

tell()

Return the current stream position.

Returns:

Stream position.

Return type:

int

truncate()

Truncate file to size bytes.

File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Returns the new size.

writable()

Return True if the stream supports writing.

If False, write() and truncate() will raise OSError.

Returns:

Supports writing.

Return type:

bool

write(b)

Write into the object.

Write the given bytes-like object, b, to the underlying raw stream, and return the number of bytes written.

Parameters:

b (bytes-like object) – Bytes to write.

Returns:

The number of bytes written.

Return type:

int

writelines(lines, /)

Write a list of lines to stream.

Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end.

class airfs.storage.azure_blob.AzurePageBlobBufferedIO(name, mode='r', buffer_size=None, max_buffers=0, max_workers=None, **kwargs)

Buffered binary Azure Page Blobs Storage Object I/O.

close()

Flush the write buffers of the stream if applicable and close the object.

detach()

Disconnect this buffer from its underlying raw stream and return it.

After the raw stream has been detached, the buffer is in an unusable state.

fileno()

Returns underlying file descriptor if one exists.

OSError is raised if the IO object does not use a file descriptor.

flush()

Flush the write buffers of the stream if applicable.

isatty()

Return whether this is an ‘interactive’ stream.

Return False if it can’t be determined.

property mode

The mode.

Returns:

Mode.

Return type:

str

property name

The file name.

Returns:

Name.

Return type:

str

peek(size=-1)

Return bytes from the stream without advancing the position.

Parameters:

size (int) – Number of bytes to read. -1 to read the full stream.

Returns:

bytes read

Return type:

bytes

property raw

The underlying raw stream.

Returns:

Raw stream.

Return type:

ObjectRawIOBase subclass

read(size=-1)

Read the object content.

Read and return up to size bytes, with at most one call to the underlying raw stream.

Use at most one call to the underlying raw stream’s read method.

Parameters:

size (int) – Number of bytes to read. -1 to read the stream until the end.

Returns:

Object content

Return type:

bytes

read1(size=-1)

Read the object content.

Read and return up to size bytes, with at most one call to the underlying raw stream.

Use at most one call to the underlying raw stream’s read method.

Parameters:

size (int) – Number of bytes to read. -1 to read the stream until the end.

Returns:

Object content

Return type:

bytes

readable()

Return True if the stream can be read from.

If False, read() will raise OSError.

Returns:

Supports reading.

Return type:

bool

readinto(b)

Read the object content into a buffer.

Read bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read.

Parameters:

b (bytes-like object) – buffer.

Returns:

number of bytes read

Return type:

int

readinto1(b)

Read the object content into a buffer.

Read bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read.

Use at most one call to the underlying raw stream’s readinto method.

Parameters:

b (bytes-like object) – buffer.

Returns:

number of bytes read

Return type:

int

readline(size=-1, /)

Read and return a line from the stream.

If size is specified, at most size bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

readlines(hint=-1, /)

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

seek(offset, whence=0)

Change the stream position to the given byte offset.

Parameters:
  • offset – Offset is interpreted relative to the position indicated by whence.

  • whence – The default value for whence is SEEK_SET. Values are: SEEK_SET or 0 – Start of the stream (the default); offset should be zero or positive SEEK_CUR or 1 – Current stream position; offset may be negative SEEK_END or 2 – End of the stream; offset is usually negative

Returns:

The new absolute position.

Return type:

int

seekable()

Return True if the stream supports random access.

If False, seek(), tell() and truncate() will raise OSError.

Returns:

Supports random access.

Return type:

bool

tell()

Return the current stream position.

Returns:

Stream position.

Return type:

int

truncate()

Truncate file to size bytes.

File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Returns the new size.

writable()

Return True if the stream supports writing.

If False, write() and truncate() will raise OSError.

Returns:

Supports writing.

Return type:

bool

write(b)

Write into the object.

Write the given bytes-like object, b, to the underlying raw stream, and return the number of bytes written.

Parameters:

b (bytes-like object) – Bytes to write.

Returns:

The number of bytes written.

Return type:

int

writelines(lines, /)

Write a list of lines to stream.

Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end.

class airfs.storage.azure_blob.AzurePageBlobRawIO(name, mode='r', **kwargs)

Binary Azure Page Blobs Storage Object I/O.

close()

Flush the write buffers of the stream if applicable and close the object.

fileno()

Returns underlying file descriptor if one exists.

OSError is raised if the IO object does not use a file descriptor.

flush()

Flush.

Flush the write buffers of the stream if applicable and save the object on the storage.

isatty()

Return whether this is an ‘interactive’ stream.

Return False if it can’t be determined.

property mode

The mode.

Returns:

Mode.

Return type:

str

property name

The file name.

Returns:

Name.

Return type:

str

readable()

Return True if the stream can be read from.

If False, read() will raise OSError.

Returns:

Supports reading.

Return type:

bool

readall()

Read and return all the bytes from the stream until EOF.

Returns:

Object content

Return type:

bytes

readinto(b)

Read the object content into a buffer.

Read bytes into a pre-allocated, writable bytes-like object b, and return the number of bytes read.

Parameters:

b (bytes-like object) – buffer.

Returns:

number of bytes read

Return type:

int

readline(size=-1, /)

Read and return a line from the stream.

If size is specified, at most size bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.

readlines(hint=-1, /)

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

seek(offset, whence=0)[source]

Change the stream position to the given byte offset.

Parameters:
  • offset – Offset is interpreted relative to the position indicated by whence.

  • whence – The default value for whence is SEEK_SET. Values are: SEEK_SET or 0 – Start of the stream (the default); offset should be zero or positive SEEK_CUR or 1 – Current stream position; offset may be negative SEEK_END or 2 – End of the stream; offset is usually negative

Returns:

The new absolute position.

Return type:

int

seekable()

Return True if the stream supports random access.

If False, seek(), tell() and truncate() will raise OSError.

Returns:

Supports random access.

Return type:

bool

tell()

Return the current stream position.

Returns:

Stream position.

Return type:

int

truncate()

Truncate file to size bytes.

File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Returns the new size.

writable()

Return True if the stream supports writing.

If False, write() and truncate() will raise OSError.

Returns:

Supports writing.

Return type:

bool

write(b)

Write into the object.

Write the given bytes-like object, b, to the underlying raw stream, and return the number of bytes written.

Parameters:

b (bytes-like object) – Bytes to write.

Returns:

The number of bytes written.

Return type:

int

writelines(lines, /)

Write a list of lines to stream.

Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end.