Answers for "javascript file size in mb"

5

python file size

>>> import os
>>> b = os.path.getsize("/path/isa_005.mp3")
>>> b
2071611
Posted by: Guest on May-14-2020
1

php get size of file

$fileSizeInBytes=filesize("/path/to/myfile.txt");
Posted by: Guest on October-22-2019
1

javascript file size in mb

function calc_file_size (bytes) {
  if (bytes >= 1073741824) {	// 1024 * 1024 * 1024
    bytes = (bytes / 1073741824) + ' GB';

  } else if (bytes >= 1048576) { // 1024 * 1024
    bytes = (bytes / 1048576) + ' MB';

  } else if (bytes >= 1024) {	// 1024 * 1
    bytes = (bytes / 1024) + ' KB';

  } else if (bytes > 1) {
    bytes = bytes + ' bytes';

  } else if ($bytes == 1) {
    bytes = bytes + ' byte';

  } else {
    bytes = '0 bytes';
  }

  return bytes;
}
Posted by: Guest on October-12-2021
1

javascrpt formatBytes

function niceBytes(x){
 const units = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  let l = 0, n = parseInt(x, 10) || 0;
  while(n >= 1024 && ++l){
      n = n/1024;
  }
  return(n.toFixed(n < 10 && l > 0 ? 1 : 0) + ' ' + units[l]);
}
Posted by: Guest on July-09-2020
1

javascrpt formatBytes

function formatBytes(bytes, decimals = 2) {
    if (bytes === 0) return '0 Bytes';

    const k = 1024;
    const dm = decimals < 0 ? 0 : decimals;
    const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

    const i = Math.floor(Math.log(bytes) / Math.log(k));

    return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
Posted by: Guest on July-09-2020

Code answers related to "javascript file size in mb"

Code answers related to "Javascript"

Browse Popular Code Answers by Language