In computing (specifically data transmission and data storage), a block,

<syntaxhighlight lang="csharp">

using System.IO;

static const int BLOCK_SIZE = 4096;

using (FileStream stream = File.Open("example.bin", FileMode.Open))

{

byte[] block = new byte[BLOCK_SIZE];

await stream.ReadAsync(block, 0, BLOCK_SIZE);

}

</syntaxhighlight>

Java

In Java, a block can be read using <code>java.io.FileInputStream</code>.

<syntaxhighlight lang="java">

import java.io.FileInputStream;

import java.io.IOException;

static final int BLOCK_SIZE = 4096;

try (FileInputStream file = new FileInputStream("example.bin")) {

byte[] buf = new byte[BLOCK_SIZE];

file.read(buf);

} catch (IOException e) {

e.printStackTrace();

}

</syntaxhighlight>

Python

In Python, a block can be read with the method of whatever is implementing <code>io.IOBase</code>.

<syntaxhighlight lang="python">

BLOCK_SIZE: int = 4096

with open("example.bin", "rb") as file:

  1. file is of type io.BufferedReader

block: bytes = file.read(BLOCK_SIZE)

</syntaxhighlight>

Rust

In Rust, a block can be read with the method of <code>std::fs::File</code>.

<syntaxhighlight lang="rust">

use std::fs::File;

const BLOCK_SIZE: usize = 4096;

if let Ok(mut file) = File::open("example.bin")

{

let mut buf = [0u8; BLOCK_SIZE];

file.read_exact(&mut buf);

}

</syntaxhighlight>

References

</references>