AIOFile

サマリー

Contains methods that perform file-related operations such as seek, tell, read, and write.

説明

This class cannot be instantiated directly. An instance of this class is returned by the AIO object's open method.

プロパティ

プロパティ説明データ タイプ
cloud
(読み取り専用)

An instance of a class that has cloud-specific methods. It is used to retrieve details of the cloud store that was used when the AIOFile object was created.

Returns an CloudFileOp object.

cloud_io = AIO(r"C:\data\datacloud.acs")
rcsfile = cloud_io.open(r'testfile.txt', 'r')
rcsfile.cloud.clearcache()
Object

方法の概要

方法説明
close ()

Flushes and closes the open file handle.

flush ()

Flushes the write buffers of the file.

read (size)

Reads data from an object and returns binary or text depending on the opened items.

rewind ()

Resets the stream position to the start.

seek (offset, {whence})

Changes the stream position to the specified byte offset.

tell ()

Returns the current stream position.

write (b)

Writes data to a local file or cloud object.

方法

close ()

For cloud stores, the cloud BLOBs are generated at closing.

rcsfile = cloud_io.open(r'cog.txt', 'r')
rcsfile.close()
flush ()
rcsfile = cloud_io.open(r'cog.txt', 'r')
rcsfile.flush()
read (size)
パラメーター説明データ タイプ
size

The number of bytes that will be read. A value of -1 reads all the content.

Integer
戻り値
データ タイプ説明
String

Returns binary or text (bytes or string) depending on the opened items.

from arcpy import AIO
cloud_io = AIO(r"C:\data\datacloud.acs")
rcsfile = cloud_io.open(r'testfile.txt', 'r')
rcsfile.read(size=4)
rcsfile.close()
from arcpy import AIO
cloud_io = AIO(r"C:\data\datacloud.acs")
with cloud_io.open(r'testfile.txt', 'r') as rcsfile:
    rcsfile.read(size=4)
rewind ()
cloud_io = AIO(r"C:\data\datacloud.acs")
rcsfile = cloud_io.open(r'testfile.txt', 'r')
rcsfile.rewind()
seek (offset, {whence})
パラメーター説明データ タイプ
offset

The number of bytes that will be read. A value of -1 reads all the content.

(デフォルト値は次のとおりです -1)

Integer
whence

Specifies how the file position indicator will be set.

  • os.SEEK_SET—The position will be set relative to the beginning of the file.
  • os.SEEK_CUR—The position will be set relative to the current file position.
  • os.SEEK_END—The position will be set relative to the end of the file.

A nonzero value for os.SEEK_CUR or os.SEEK_END is not supported for local files when the file is opened in a nonbinary mode.

Object
import os
rcsfile = cloud_io.open(r'cog.txt', 'r')
rcsfile.seek(offset=6, whence=os.SEEK_CUR)
tell ()
戻り値
データ タイプ説明
Integer

The current stream position.

rcsfile = cloud_io.open(r'cog.tif', 'rb')
print(rcsfile.tell())
write (b)
パラメーター説明データ タイプ
b

The data that will be written.

String
戻り値
データ タイプ説明
Integer

The number of bytes written.

from arcpy import AIO
local_io = AIO(r"C:\data")
rcsfile = local_io.open(r'testfile.txt', 'r')
rcsfile.write("This is a test file.")
rcsfile.close()
from arcpy import AIO
cloud_io = AIO(r"C:\data\datacloud.acs")
rcsfile = cloud_io.open(r"C:\data\info\datafile.txt", 'w', mime={'Content-Type': 'text/plain'})
rcsfile.write("This is a test file.")
rcsfile.close()
# Using with statement (context manager to close the opened file)
cloud_io = AIO(r"C:\data\datacloud.acs")
with cloud_io.open(r"C:\data\info\datafile.txt", 'w', mime={'Content-Type': 'text/plain'}) as rcsfile:
    rcsfile.write("This is a test file.")