Coder Social home page Coder Social logo

remote-file-size's Introduction

remote-file-size

Build Status Coverage Status

Get the size of a remote file

Note: remote-file-size is only supported on iojs and node v4+. To use with an older version of node, please use remote-file-size@2.

Install

$ npm install --save remote-file-size
# or for the cli tool
$ npm install -g remote-file-size

Usage

$ remote-file-size http://registry.npmjs.org/argsplit/-/argsplit-1.0.2.tgz
// => 1.55 kB
var remote = require('remote-file-size')
var url = 'http://registry.npmjs.org/argsplit/-/argsplit-1.0.2.tgz'
remote(url, function(err, o) {
  console.log(o)
  // => 1548
})

CLI Usage

$ remote-file-size --help

remote-file-size - get the size of a remote file

  usage: remote-file-size [options] <url>

  options:
    -h, --help                  show help and usage
    -v, --version               show version
    -r, --raw                   show raw result (no pretty formatting)
    -f, --follow-redirect       follow redirects (true by default)
    -m, --max-redirects <num>   set max number of redirects (defaults to 2)

  example:
    remote-file-size http://registry.npmjs.org/argsplit/-/argsplit-1.0.2.tgz
    // => 1.55 kB

    remote-file-size --raw http://registry.npmjs.org/argsplit/-/argsplit-1.0.2.tgz
    // => 1548

remote-file-size uses request under the hood, so you could also pass an options object instead of the url string.

Author

Evan Lucas

License

MIT (See LICENSE for more info)

remote-file-size's People

Contributors

abrahamd avatar ca333 avatar evanlucas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

remote-file-size's Issues

Security Warnings

There are a few security warnings, if you use "remote-file-size" because of the dependencies:

┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Prototype pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ > 4.2.0 < 5.0.0 || >= 5.0.3                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ remote-file-size                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ remote-file-size > request > hawk > boom > hoek              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/566                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Prototype pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ > 4.2.0 < 5.0.0 || >= 5.0.3                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ remote-file-size                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ remote-file-size > request > hawk > cryptiles > boom > hoek  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/566                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Prototype pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ > 4.2.0 < 5.0.0 || >= 5.0.3                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ remote-file-size                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ remote-file-size > request > hawk > hoek                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/566                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Prototype pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ > 4.2.0 < 5.0.0 || >= 5.0.3                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ remote-file-size                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ remote-file-size > request > hawk > sntp > hoek              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/566                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Out-of-bounds Read                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ stringstream                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ remote-file-size                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ remote-file-size > request > stringstream                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/664                       │
└───────────────┴──────────────────────────────────────────────────────────────┘

:clap:

I searched duckduckgo for remote file size cli and this popped up. Exactly what I was looking for. Thanks for writing it!

vulnerabilities related to tap

found 12 vulnerabilities (5 low, 1 moderate, 5 high, 1 critical) in 300 scanned packages
12 vulnerabilities require semver-major dependency updates.

it looks like all vulns are related to tap

https urls throw error

if a url has https then the module throws errors.
{ Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1177:34)
at TLSSocket.emit (events.js:197:13)
at TLSSocket._finishInit (_tls_wrap.js:668:8) code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }

https urls throw error

if a url has https then the module throws errors.
{ Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1177:34)
at TLSSocket.emit (events.js:197:13)
at TLSSocket._finishInit (_tls_wrap.js:668:8) code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }

Error: Unable to determine file size

Using https://github.com/adamisntdead/poke an error is thrown that seems to be from this library

Error: Unable to determine file size
    at Request._callback (/home/lewis/.nvm/versions/node/v8.9.4/lib/node_modules/poke-site/node_modules/remote-file-size/index.js:26:17)
    at Request.self.callback (/home/lewis/.nvm/versions/node/v8.9.4/lib/node_modules/poke-site/node_modules/request/request.js:188:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (/home/lewis/.nvm/versions/node/v8.9.4/lib/node_modules/poke-site/node_modules/request/request.js:1171:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (/home/lewis/.nvm/versions/node/v8.9.4/lib/node_modules/poke-site/node_modules/request/request.js:1091:12)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1055:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

Example URL: https://www.stormykromer.com/giftcertificates.php

No idea why but it's across BigCommerce software, so maybe no content-length header in response?

Are you aware of any way to handle other than throwing an error?

tests do not succeed

it seems like tests depend on some external resource which is not available?

Version:

commit 1028b533bb1730311ef4ec1257f6f8f25725a998 (HEAD -> master, origin/master, origin/HEAD)
Author: ca333 <[email protected]>
Date:   Tue Aug 28 16:59:41 2018 +0200

    update travis

    removed old node versions that lead to failed build

    todo: add/test new/LTS node versons to CI scope
$ node --version
v12.9.1
$ uname -a
Darwin C02T81ZHH03Q 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64

Reproduce:

$ npm install
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: this library is no longer supported
npm notice created a lockfile as package-lock.json. You should commit this file.
added 300 packages from 179 contributors and audited 300 packages in 8.791s
found 12 vulnerabilities (5 low, 1 moderate, 5 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details

$ npm test

> [email protected] test /Users/harrinm/work/remote-file-size
> tap test.js --cov

test.js .............................................. 6/12 3m
  should return null, size on success
  not ok err should not exist
    found:
      name: Error
      stack: |-
        Error: connect ETIMEDOUT 104.16.20.35:80
            at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1056:14)
      message: 'connect ETIMEDOUT 104.16.20.35:80'
      errno: ETIMEDOUT
      code: ETIMEDOUT
      syscall: connect
      address: 104.16.20.35
      port: 80
    at:
      line: 26
      column: 7
      file: test.js
    stack: |
      test.js:26:7
      Request._callback (index.js:1:4096)
      self.callback (node_modules/request/request.js:185:22)
      Request.onRequestError (node_modules/request/request.js:877:8)
    source: |
      t.ifError(err, 'err should not exist')

  should return null, size on success
  not ok out should exist
    at:
      line: 27
      column: 7
      file: test.js
    stack: |
      test.js:27:7
      Request._callback (index.js:1:4096)
      self.callback (node_modules/request/request.js:185:22)
      Request.onRequestError (node_modules/request/request.js:877:8)
    source: |
      t.ok(out, 'out should exist')

  should return null, size on success
  not ok should be equal
    --- wanted
    +++ found
    -1548
    +[null]
    compare: '==='
    at:
      line: 28
      column: 7
      file: test.js
    stack: |
      test.js:28:7
      Request._callback (index.js:1:4096)
      self.callback (node_modules/request/request.js:185:22)
      Request.onRequestError (node_modules/request/request.js:877:8)
    source: |
      t.equal(out, 1548)

  should work passing an object
  not ok err should not exist
    found:
      name: Error
      stack: |-
        Error: connect ETIMEDOUT 104.16.20.35:80
            at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1056:14)
      message: 'connect ETIMEDOUT 104.16.20.35:80'
      errno: ETIMEDOUT
      code: ETIMEDOUT
      syscall: connect
      address: 104.16.20.35
      port: 80
    at:
      line: 39
      column: 7
      file: test.js
    stack: |
      test.js:39:7
      Request._callback (index.js:1:4096)
      self.callback (node_modules/request/request.js:185:22)
      Request.onRequestError (node_modules/request/request.js:877:8)
    source: |
      t.ifError(err, 'err should not exist')

  should work passing an object
  not ok out should exist
    at:
      line: 40
      column: 7
      file: test.js
    stack: |
      test.js:40:7
      Request._callback (index.js:1:4096)
      self.callback (node_modules/request/request.js:185:22)
      Request.onRequestError (node_modules/request/request.js:877:8)
    source: |
      t.ok(out, 'out should exist')

  should work passing an object
  not ok should be equal
    --- wanted
    +++ found
    -1548
    +[null]
    compare: '==='
    at:
      line: 41
      column: 7
      file: test.js
    stack: |
      test.js:41:7
      Request._callback (index.js:1:4096)
      self.callback (node_modules/request/request.js:185:22)
      Request.onRequestError (node_modules/request/request.js:877:8)
    source: |
      t.equal(out, 1548)

total ................................................ 6/12


  6 passing (3m)
  6 failing

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |    80.95 |    66.67 |      100 |       80 |                   |
 index.js |    80.95 |    66.67 |      100 |       80 |       28,29,30,33 |
----------|----------|----------|----------|----------|-------------------|
npm ERR! Test failed.  See above for more details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.