---
title: "IO.FileStream"
description: "IO file stream prototype."
canonical_url: "https://www.zeyos.com/zymba/ref/io/io-filestream"
markdown_url: "https://www.zeyos.com/ai/guide/zymba/ref/io/io-filestream.md"
section: "zymba-reference"
authority: "reference"
language: "en"
source_repository: "https://cloud.zeyos.com/__doc/zymbaref.json"
source_sha256: "05a361c6ddc32e74f4a6dc16fd06f218210ff1b7ce57f26ca1994bfffc407915"
---

# IO.FileStream

## IO.FileStream

```
object @IO.FileStream(@IO.Stream) {
	MODE_CREATE;
	MODE_TRUNCATE;
	MODE_APPEND;
	MODE_OVERWRITE;
	construct(string $path, int $mode) {}
	attemptLock(): bool {}
	attemptLockShared(): bool {}
	canLock(): bool {}
	getSize(): int {}
	lock(): $this {}
	lockShared(): $this {}
	pad(int $size, string $padding): int {}
	selectLock(): object {}
	sync(): bool {}
	syncData(): bool {}
	unlock(): $this {}
}
```

**IO file stream prototype.**

### Prototype

**[IO.Stream](#)**

## Methods


### `$this.construct()`


Opens a stream to a file in a specific access mode (see MODE_* constants).

```code
$this.construct(string $path, int $mode): void
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| path | `string`  |  | "" |
| mode | `int`  |  | MODE_READ | MODE_WRITE | MODE_CREATE |




### `$this.attemptLock()`


```code
$this.attemptLock(): bool
```

##### Returns

| Type | Value |
| --- | ---  |
| `bool` |  |




### `$this.attemptLockShared()`


```code
$this.attemptLockShared(): bool
```

##### Returns

| Type | Value |
| --- | ---  |
| `bool` |  |




### `$this.canLock()`


Determines whether this stream can be locked.

```code
$this.canLock(): bool
```

##### Returns

| Type | Value |
| --- | ---  |
| `bool` |  |




### `$this.getSize()`


Gets the size of this stream in number of bytes.

```code
$this.getSize(): int
```

##### Returns

| Type | Value |
| --- | ---  |
| `int` |  |




### `$this.lock()`


```code
$this.lock(): this
```

##### Returns

| Type | Value |
| --- | ---  |
| `$this` |  |




### `$this.lockShared()`


```code
$this.lockShared(): this
```

##### Returns

| Type | Value |
| --- | ---  |
| `$this` |  |




### `$this.pad()`


Pads the content of this stream to a specific size in number of bytes by repeatedly appending it with a specific padding string and returns the number of bytes written.

```code
$this.pad(int $size, string $padding): int
```

##### Parameters

| Name | Type | Value | Default |
| --- | --- | --- | --- |
| size | `int`  |  | 0 |
| padding | `string`  |  | "\x00" |

##### Returns

| Type | Value |
| --- | ---  |
| `int` |  |




### `$this.selectLock()`


```code
$this.selectLock(): @IO.LockContext
```

##### Returns

| Type | Value |
| --- | ---  |
| `@IO.LockContext` |  |




### `$this.sync()`


Synchonizes this stream with the underlying storage device, including modified metadata.

```code
$this.sync(): bool
```

##### Returns

| Type | Value |
| --- | ---  |
| `bool` |  |




### `$this.syncData()`


Synchonizes this stream with the underlying storage device, excluding modified metadata (if possible).

```code
$this.syncData(): bool
```

##### Returns

| Type | Value |
| --- | ---  |
| `bool` |  |




### `$this.unlock()`


```code
$this.unlock(): this
```

##### Returns

| Type | Value |
| --- | ---  |
| `$this` |  |
