code: def test_binary_writer_with_jpeg_and_int(tmpdir):
      """Validate the writer and reader can serialize / deserialize a pair of image and label."""
      from PIL import Image
  
      cache_dir = os.path.join(tmpdir, "chunks")
      os.makedirs(cache_dir, exist_ok=True)
      binary_writer = BinaryWriter(cache_dir, chunk_bytes=2 << 12)
  
      imgs = []
  
      for i in range(100):
          path = os.path.join(tmpdir, f"img{i}.jpeg")
          np_data = np.random.randint(
              255, size=(28, 28), dtype=np.uint8
          )
          img = Image.fromarray(np_data).convert("L")
          img.save(path, format="jpeg", quality=100)
          img = Image.open(path)
          imgs.append(img)
          binary_writer[i] = {"x": img, "y": i}
  
      assert len(os.listdir(cache_dir)) == 24
      binary_writer.done()
      binary_writer.merge()
      assert len(os.listdir(cache_dir)) == 26
  
      with open(os.path.join(cache_dir, "index.json")) as f:
          data = json.load(f)
  
      assert data["chunks"][0]["chunk_size"] == 4
      assert data["chunks"][1]["chunk_size"] == 4
      assert data["chunks"][-1]["chunk_size"] == 4
  
      reader = BinaryReader(cache_dir, max_cache_size=10 ^ 9)
      for i in range(100):
          data = reader.read(ChunkedIndex(i, chunk_index=i // 4))
          np.testing.assert_array_equal(
              np.asarray(data["x"]).squeeze(0), imgs[i]
          )
          assert data["y"] == i
  
file_path: pytorch-lightning/tests/tests_data/streaming/test_writer.py
imports: import json
  import os
  import sys
  import numpy
  import pytest
  from lightning import seed_everything
  from lightning.data.streaming.reader import BinaryReader
  from lightning.data.streaming.sampler import ChunkedIndex
  from lightning.data.streaming.writer import BinaryWriter
  from lightning.data.utilities.format import _FORMAT_TO_RATIO
  from lightning_utilities.core.imports import RequirementCache
label_desc: Use image node_id 3 for calling a global function with example usage: test_binary_writer_with_jpeg_and_int(tmpdir) without return types