> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/aistore/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/aistore/_mcp/server.

# aistore.sdk.batch.multipart.sliding_window_buffer

## Module Contents

### Classes

| Name                                                                                            | Description                                                                     |
| ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| [`SlidingWindowBuffer`](#aistore-sdk-batch-multipart-sliding_window_buffer-SlidingWindowBuffer) | High-performance sliding window buffer optimized for streaming data processing. |

### API

```python
class aistore.sdk.batch.multipart.sliding_window_buffer.SlidingWindowBuffer(
    max_size: int,
    boundary_size: int
)
```

High-performance sliding window buffer optimized for streaming data processing.

The buffer automatically manages memory by sliding the window when it reaches
capacity, keeping only the most recent data plus a configurable overlap for
cross-chunk pattern detection.

**Parameters:**

Maximum logical size before sliding window activation

Size of boundary pattern for overlap calculations

```python
aistore.sdk.batch.multipart.sliding_window_buffer.SlidingWindowBuffer.__len__() -> int
```

Return current logical length of valid data in buffer.

**Returns:** `int`

Number of bytes of valid data

```python
aistore.sdk.batch.multipart.sliding_window_buffer.SlidingWindowBuffer._compact_buffer() -> None
```

Compact buffer by moving valid data to beginning and updating position tracking.

```python
aistore.sdk.batch.multipart.sliding_window_buffer.SlidingWindowBuffer._get_data(
    start: int = 0,
    end: typing.Optional[int] = None
) -> memoryview
```

Get a data slice without copying using memoryview for efficiency.

WARNING: The returned memoryview is only valid until the next call to
append(), consume(), or any other method that modifies the buffer.
For long-term storage, use get\_data\_bytes() instead.

**Parameters:**

Starting position. Defaults to 0.

Ending position, None for end of buffer.

**Returns:** `memoryview`

Memory view of requested data range (TEMPORARY)

```python
aistore.sdk.batch.multipart.sliding_window_buffer.SlidingWindowBuffer.append(
    data: bytes
) -> None
```

Append data to buffer with automatic sliding window management and compaction.

**Parameters:**

Data to append to the buffer

```python
aistore.sdk.batch.multipart.sliding_window_buffer.SlidingWindowBuffer.clear() -> None
```

Clear the buffer and update total processed byte counter.

```python
aistore.sdk.batch.multipart.sliding_window_buffer.SlidingWindowBuffer.consume(
    length: int
) -> bytes
```

Consume and return data from start of buffer, advancing the window.

**Parameters:**

Number of bytes to consume

**Returns:** `bytes`

Consumed data

```python
aistore.sdk.batch.multipart.sliding_window_buffer.SlidingWindowBuffer.find(
    pattern: bytes,
    start: int = 0
) -> int
```

Find pattern in buffer and return absolute position in stream.

**Parameters:**

Pattern to search for

Starting offset for search. Defaults to 0.

**Returns:** `int`

Absolute position if found, -1 if not found

```python
aistore.sdk.batch.multipart.sliding_window_buffer.SlidingWindowBuffer.find_relative(
    pattern: bytes,
    start: int = 0
) -> int
```

Find pattern in buffer and return position relative to current buffer window.

**Parameters:**

Pattern to search for

Starting offset for search. Defaults to 0.

**Returns:** `int`

Relative position if found, -1 if not found

```python
aistore.sdk.batch.multipart.sliding_window_buffer.SlidingWindowBuffer.get_data_bytes(
    start: int = 0,
    end: typing.Optional[int] = None
) -> bytes
```

Get data as bytes by creating a copy of the requested range.

**Parameters:**

Starting position. Defaults to 0.

Ending position, None for end of buffer

**Returns:** `bytes`

Copy of requested data range

```python
aistore.sdk.batch.multipart.sliding_window_buffer.SlidingWindowBuffer.skip_leading_whitespace() -> int
```

Skip leading whitespace characters and return count of bytes skipped.

**Returns:** `int`

Number of whitespace bytes that were skipped and consumed