CBFSStorageStream Type

Syntax

CBFSStorageStream (declared in cbfsstorage.h for C++, and in CBFSStorageStreams.h for Objective-C/Swift)

Remarks

The CBFSStorageStream type is returned by some of the CBDrive class's methods. All stream types in CBFS Storage share a common API, documented below.

This type provides a custom streaming API with full read, write, and seek functionality. To interact with a stream via conventional Objective-C streaming APIs, use the inputStream and outputStream methods to obtain an NSInputStream or NSOutputStream object.
This type provides a custom streaming API with full read, write, and seek functionality. To interact with a stream via conventional Swift streaming APIs, use the inputStream and outputStream methods to obtain an InputStream or OutputStream object.

Properties

Length Gets or sets the length of the stream, in bytes.

int64 GetLength();
void SetLength(int64 length);
Position Gets or sets the current position within the stream.

int64 GetPosition();
void SetPosition(int64 position);

Methods

Close Closes the stream, releasing all resources currently allocated for it.

void Close();

This method is called automatically when a CBFSStorageStream object is deleted.

Flush Forces all data held by the stream's buffers to be written out to storage.

void Flush();
GetLastError If the previous operation failed, returns the associated error message, if any.

char* GetLastError();
GetLastErrorCode If the previous operation failed, returns a non-zero error code; otherwise returns zero.

int GetLastErrorCode();

This method will always return -1 after Close has been called.

Read Reads a sequence of bytes from the stream and advances the current position within the stream by the number of bytes read.

int Read(void* buffer, int count);

Buffer specifies the buffer to populate with data from the stream. Count specifies the number of bytes that should be read from the stream.

Returns the total number of bytes read into Buffer. This may be less than Count if that many bytes are not currently available, or may be 0 if the end of the stream has been reached.

Seek Sets the current position within the stream based on a particular point of origin.

int64 Seek(int64 offset, SeekOrigin origin);

enum SeekOrigin { soFromBeginning = 0, soFromCurrent = 1, soFromEnd = 2 };

Offset specifies the offset in the stream to seek to, relative to Origin. SeekOrigin is an enum declared alongside the CBFSStorageStream class as shown above.

Returns the new position within the stream.

Write Writes a sequence of bytes to the stream and advances the current position within the stream by the number of bytes written.

int Write(void* buffer, int count);

Buffer specifies the buffer with data to write to the stream. Count specifies the number of bytes that should be written to the stream.

Returns the total number of bytes written to the stream.

Properties

length Gets or sets the length of the stream, in bytes.

@property (nonatomic,readwrite,assign,getter=length,setter=setLength:) long long length;
- (long long)length;
- (void)setLength:(long long)newLength;
position Gets or sets the current position within the stream.

@property (nonatomic,readwrite,assign,getter=position,setter=setPosition:) long long position;
- (long long)position;
- (void)setPosition:(long long)newPosition;

Methods

close Closes the stream, releasing all resources currently allocated for it.

- (void)close;

Closing a CBFSStorageStream instance invalidates any stream objects that have been created using its inputStream and outputStream methods. This method is called automatically when a CBFSStorageStream object is released.

flush Forces all data held by the stream's buffers to be written out to storage.

- (void)flush;
inputStream Returns a standard Objective-C NSInputStream tied to the current CBFSStorageStream instance.

- (NSInputStream*)inputStream;

The NSInputStream instance is returned in an "opened" state initially; when it is closed, the CBFSStorageStream instance that returned it is also closed (which, as close describes, causes all other standard stream objects tied to that CBFSStorageStream instance to be invalidated).

lastError If the previous operation failed, returns the associated error message, if any.

- (NSString*)lastError;
lastErrorCode If the previous operation failed, returns a non-zero error code; otherwise returns zero.

- (int)lastErrorCode;

This method will always return -1 after close has been called.

outputStream Returns a standard Objective-C NSOutputStream tied to the current CBFSStorageStream instance.

- (NSOutputStream*)outputStream;

The NSOutputStream instance is returned in an "opened" state initially; when it is closed, the CBFSStorageStream instance that returned it is also closed (which, as close describes, causes all other standard stream objects tied to that CBFSStorageStream instance to be invalidated).

read Reads a sequence of bytes from the stream and advances the current position within the stream by the number of bytes read.

- (int)read:(void*)buffer :(int)count;

buffer specifies the buffer to populate with data from the stream. count specifies the number of bytes that should be read from the stream.

Returns the total number of bytes read into buffer. This may be less than count if that many bytes are not currently available, or may be 0 if the end of the stream is reached. Returns -1 if an error occurs or the stream is closed.

seek Sets the current position within the stream based on a particular point of origin.

- (long long)seek:(long long)offset :(int)origin;

offset specifies the offset in the stream to seek to, relative to origin, which must be one of the following (declared at the top of CBFSStorageStreams.h):

  • STREAM_SEEK_FROM_BEGIN (0)
  • STREAM_SEEK_FROM_CURRENT (1)
  • STREAM_SEEK_FROM_END (2)

Returns the new position within the stream.

write Writes a sequence of bytes to the stream and advances the current position within the stream by the number of bytes written.

- (int)write:(void*)buffer :(int)count;

buffer specifies the buffer with data to write to the stream. count specifies the number of bytes that should be written to the stream.

Returns the total number of bytes written to the stream, or -1 if an error occurs or the stream is closed.

Properties

length Gets or sets the length of the stream, in bytes.

public var length: Int64 {
get {...}
set {...}
}
position Gets or sets the current position within the stream.

public var position: Int64 {
get {...}
set {...}
}

Methods

close Closes the stream, releasing all resources currently allocated for it.

public func close() -> Void

Closing a CBFSStorageStream instance invalidates any stream objects that have been created using its inputStream and outputStream methods. This method is called automatically when a CBFSStorageStream object is released.

flush Forces all data held by the stream's buffers to be written out to storage.

public func flush() -> Void
inputStream Returns a standard Swift InputStream tied to the current CBFSStorageStream instance.

public func inputStream() -> InputStream

The InputStream instance is returned in an "opened" state initially; when it is closed, the CBFSStorageStream instance that returned it is also closed (which, as close describes, causes all other standard stream objects tied to that CBFSStorageStream instance to be invalidated).

lastError If the previous operation failed, returns the associated error message, if any.

public func lastError() -> String
lastErrorCode If the previous operation failed, returns a non-zero error code; otherwise returns zero.

public func lastErrorCode() -> Int32

This method will always return -1 after close has been called.

outputStream Returns a standard Swift OutputStream tied to the current CBFSStorageStream instance.

public func outputStream() -> OutputStream

The OutputStream instance is returned in an "opened" state initially; when it is closed, the CBFSStorageStream instance that returned it is also closed (which, as close describes, causes all other standard stream objects tied to that CBFSStorageStream instance to be invalidated).

read Reads a sequence of bytes from the stream and advances the current position within the stream by the number of bytes read.

public func read(_ buffer: UnsafeRawPointer, _ count: Int32) -> Int32

buffer specifies the buffer to populate with data from the stream. count specifies the number of bytes that should be read from the stream.

Returns the total number of bytes read into buffer. This may be less than count if that many bytes are not currently available, or may be 0 if the end of the stream is reached. Returns -1 if an error occurs or the stream is closed.

seek Sets the current position within the stream based on a particular point of origin.

public func seek(_ offset: Int64, _ origin: Int32) -> Int64

offset specifies the offset in the stream to seek to, relative to origin, which must be one of the following (declared at the top of CBFSStorageStreams.h):

  • STREAM_SEEK_FROM_BEGIN (0)
  • STREAM_SEEK_FROM_CURRENT (1)
  • STREAM_SEEK_FROM_END (2)

Returns the new position within the stream.

write Writes a sequence of bytes to the stream and advances the current position within the stream by the number of bytes written.

public func write(_ buffer: UnsafeRawPointer, _ count: Int32) -> Int32

buffer specifies the buffer with data to write to the stream. count specifies the number of bytes that should be written to the stream.

Returns the total number of bytes written to the stream, or -1 if an error occurs or the stream is closed.

Copyright (c) 2021 Callback Technologies, Inc. - All rights reserved.
CBFS Storage 2020 C++ Edition - Version 20.0 [Build 8031]