get_number_of_chunks

pyhelpers.ops.get_number_of_chunks(file_or_obj, chunk_size_limit=50, binary=True)[source]

Get the total number of chunks of a data file, given a minimum chunk size limit.

Parameters:
  • file_or_obj (Any) – Path to a file or an object representing the data.

  • chunk_size_limit (int | float | None) – Minimum limit of chunk size in megabytes (MB) or mebibytes (MiB) above which the function counts the number of chunks; defaults to 50.

  • binary (bool) – Whether to use binary (factorised by 1024) or decimal (factorised by 10 ** 3) representation for size calculations; defaults to True for binary representation.

Returns:

Number of chunks, or None if file_or_obj is invalid or chunk calculation is not applicable.

Return type:

int | None

Examples:

>>> from pyhelpers.ops import get_number_of_chunks
>>> import numpy
>>> example_obj = numpy.zeros((1000, 1000))
>>> get_number_of_chunks(example_obj, chunk_size_limit=5)
2
>>> file_path = "C:\Program Files\Python310\python310.pdb"
>>> get_number_of_chunks(file_path, chunk_size_limit=2)
8