InMemoryDiskIo

A DiskIo that keeps the whole torrent in one in-memory buffer. The BitTorrent piece model treats the files as a single concatenated byte stream, so piece p lives at p * pieceLength within that stream, which is exactly this buffer. Per-file boundaries only matter when writing to real files (FileDiskIo); here one buffer is the simplest correct model.

This is the engine's test workhorse: deterministic, no I/O, no platform deps.

Constructors

Link copied to clipboard
constructor(storage: FileStorage)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The current save path (defaults to empty until move is called).

Functions

Link copied to clipboard
open suspend override fun checkExistingFiles(): BooleanArray

Which pieces do we already have on disk? Drives the initial resume/recheck.

Link copied to clipboard
open suspend override fun close()

Release file handles and stop.

Link copied to clipboard
fun fileName(fileIndex: Int): String

The effective name of fileIndex after any rename (its original path otherwise).

Link copied to clipboard
open suspend override fun flush()

Flush any buffered writes to durable storage.

Link copied to clipboard
open suspend override fun hashPiece(piece: Int): PieceHashes

Hash a fully-downloaded piece for verification against the torrent's hashes.

Link copied to clipboard
open suspend override fun move(newSavePath: String)

The torrent lives in one anonymous buffer addressed by absolute offset, so there are no on-disk paths to relocate; savePath is tracked only so callers can read back the current location, mirroring libtorrent's bookkeeping.

Link copied to clipboard
open suspend override fun read(piece: Int, offset: Int, length: Int): ByteArray

Read length bytes at offset within piece.

Link copied to clipboard
open suspend override fun rename(fileIndex: Int, newName: String)

File names are not part of the in-memory model (the buffer is addressed by offset), so a rename only updates the recorded name map for inspection by tests.

Link copied to clipboard

Direct access to the backing bytes, for tests asserting written content.

Link copied to clipboard
open suspend override fun write(piece: Int, offset: Int, data: ByteArray)

Write data at offset within piece. The bytes are owned by the callee after the call.