Instance Method インスタンスメソッド

readDataUpToLength:error:

Reads data synchronously up to the specified number of bytes.

Declaration 宣言

- (NSData *)readDataUpToLength:(NSUInteger)length 
                         error:(out NSError * _Nullable *)error;

Parameters パラメータ

length

The number of bytes to read from the file handle.

error

When the return value is nil, this provides an NSError indicating why the read operation failed.

Return Value 戻り値

The data available through the receiver up to a maximum of length bytes, or the maximum size that can be represented by an NSData object, whichever is the smaller. 最大限lengthバイト、またはNSDataオブジェクトによって表現可能な最大限サイズ、どちらかより小さい方に至るまでレシーバを通して利用可能なデータ。

Discussion 議論

If the handle represents a file, this method returns the data obtained by reading length bytes starting at the current file pointer. If length bytes aren’t available, this method returns the data from the current file pointer to the end of the file. If the handle is a communications channel, the method reads up to length bytes from the channel. Returns an empty NSData object if the handle is at the file’s end or if the communications channel returns an end-of-file indicator.

This method provides an error if attempts to determine the file-handle type fail or if attempts to read from the file or channel fail.

See Also 参照

Reading from a File Handle Synchronously ファイルハンドルから同期的に読み出す