Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

file_size_url

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file_size_url

Get file size by URL without downloading it

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

file_size_url



Get file size from URL without downloading it. 0 dependencies.

Returns Promise with 'B', 'KB', 'MB', 'GB', 'TB' on success.

npm i file_size_url


import file_size_url from 'file_size_url';

file_size_url("https://server10.mp3quran.net/bader/Rewayat-Hafs-A-n-Assem/001.mp3")
    .then(console.log) // 968.27 KB
    .catch(console.error);

OR


import file_size_url from 'file_size_url';

let size = await file_size_url("https://serverjyy10.mp3quran.net/bader/Rewayat-Hafs-A-n-Assem/0001.mp3")
    .catch((error) => console.log(error))

console.log(size) // 968.27 KB


Example for lop


let array = [

    'https://server10.mp3quran.net/bader/Rewayat-Hafs-A-n-Assem/001.mp3',
    'https://server10.mp3quran.net/bader/Rewayat-Hafs-A-n-Assem/002.mp3',
    'https://server10.mp3quran.net/bader/Rewayat-Hafs-A-n-Assem/003.mp3',
    'https://server10.mp3quran.net/bader/Rewayat-Hafs-A-n-Assem/055.mp3',
    'https://server10.mp3quran.net/bader/Rewayat-Hafs-A-n-Assem/110.mp3',

]

for (let index = 0; index < array.length; index++) {

    try {

        let fies_size = await file_size_url(array[index])

        if (fies_size.toString().split('.')[0] <= 95 && fies_size.toString().split(' ')[1] === 'MB') {

            console.log(fies_size + ' || <= 95 MB');

        }

        else if (fies_size.toString().split('.')[0] > 95 && fies_size.toString().split(' ')[1] === 'MB') {

            console.log(fies_size + ' || > 95 MB');

        }

        else if (fies_size.toString().split(' ')[1] === 'KB') {

            console.log(fies_size + ' || KB');

        }


    } catch (error) {

        console.log(error);

    }

}


/* output 
968.27 KB || KB
170.58 MB || > 95 MB
95.77 MB || <= 95 MB
12.21 MB || <= 95 MB
711.92 KB || KB
*/


Keywords

FAQs

Package last updated on 18 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc