code: def nifti_rw(self, test_data, reader, writer, dtype, resample=True):
      test_data = test_data.astype(dtype)
      ndim = len(test_data.shape) - 1
      for p in TEST_NDARRAYS:
          output_ext = ".nii.gz"
          filepath = f"testfile_{ndim}d"
          saver = SaveImage(
              output_dir=self.test_dir,
              output_ext=output_ext,
              output_dtype=None,
              resample=resample,
              separate_folder=False,
              writer=writer,
          )
          meta_dict = {
              "filename_or_obj": f"{filepath}.png",
              "affine": np.eye(4),
              "original_affine": np.array(
                  [
                      [0, 1, 0, 0],
                      [1, 0, 0, 0],
                      [0, 0, 1, 0],
                      [0, 0, 0, 1],
                  ]
              ),
          }
          test_data = MetaTensor(p(test_data), meta=meta_dict)
          self.assertEqual(test_data.meta[MetaKeys.SPACE], "RAS")
          saver(test_data)
          saved_path = os.path.join(
              self.test_dir, filepath + "_trans" + output_ext
          )
          self.assertTrue(os.path.exists(saved_path))
          loader = LoadImage(
              image_only=True,
              reader=reader,
              squeeze_non_spatial_dims=True,
              dtype=None,
          )
          data = loader(saved_path)
          self.assertIn(dtype.__name__, str(data.dtype))
          meta = data.meta
          if meta["original_channel_dim"] == -1:
              _test_data = moveaxis(test_data, 0, -1)
          else:
              _test_data = test_data[0]
          if resample:
              _test_data = moveaxis(_test_data, 0, 1)
          assert_allclose(meta["qform_code"], 1, type_test=False)
          assert_allclose(meta["sform_code"], 1, type_test=False)
          assert_allclose(data, torch.as_tensor(_test_data))
  
imports: from __future__ import annotations
  import itertools
  import os
  import shutil
  import tempfile
  import unittest
  import numpy
  import torch
  from parameterized import parameterized
  from monai.data.image_reader import ITKReader, NibabelReader, NrrdReader, PILReader
  from monai.data.image_writer import ITKWriter, NibabelWriter, PILWriter, register_writer, resolve_writer
  from monai.data.meta_tensor import MetaTensor
  from monai.transforms import LoadImage, SaveImage, moveaxis
  from monai.utils import MetaKeys, OptionalImportError, optional_import
  from tests.utils import TEST_NDARRAYS, assert_allclose
label_desc: Use image node_id 3 for calling the TestLoadSaveNifti obj's underlying member method code with example usage: obj.nifti_rw(test_data, reader, writer, dtype, resample) without return types