Package detail

get-content-length

Kikobeats466MIT1.0.9

Get content-length from the input

content-length, data, data-uri, response

readme

get-content-length

Last version Coverage Status NPM Status

Get Content-Length from the input.

Install

$ npm install get-content-length --save

Usage

The default method automagically detects the input:

const contentLength = require('get-content-length')
await contentLength('https://microlink.io/favicon.ico') // => 34494

It handles HTTP errors, such 404:

await contentLength('https://httpbin.org/status/404') // => 0

It accepts got#options as second argument:

await contentLength('https://microlink.io/favicon.ico', { timeout: 8000 }) // => 34494

Alternatively, you can explicitly call the desired method:

.fromUrl

const { fromUrl } = require('get-content-length')
await fromUrl('https://microlink.io/favicon.ico') // => 34494

.fromDataUri

const { fromDataUri } = require('get-content-length')
await contentLength.fromDataUri('data:image/png;base64,iVBORw0KGgoAAA…') // => 34494

.fromResponse

const { fromResponse } = require('get-content-length')
const reachableUrl = require('reachable-url')

const response = await reachableUrl('https://mirrors.dotsrc.org/blender/blender-demo/movies/ToS/tearsofsteel_4k.mov')
await fromResponse(response) // => 6737592810

Related

  • reachable-url — It resolves the URL as fast as possible, without downloading the body.
  • html-get — Get the HTML from any website, using prerendering when is necessary.

License

get-content-length © Kiko Beats, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.

kikobeats.com · GitHub Kiko Beats · X @Kikobeats

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.0.9 (2024-10-19)

1.0.8 (2024-10-19)

1.0.7 (2024-05-09)

1.0.6 (2023-10-07)

1.0.5 (2023-10-07)

1.0.4 (2023-09-05)

1.0.3 (2023-07-28)

1.0.2 (2023-02-11)

1.0.1 (2022-11-21)

1.0.0 (2022-11-19)

0.0.2 (2022-11-19)

0.0.1 (2022-11-19)