npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nv-buf-read-byte

v1.0.4

Published

nv-buf-read-byte =============== - nv-buf-read-byte - read just one-byte from file - this is for test nvlang's byte-stream interpreter(parse unknown code char-by-char from remote),normally USELESS

Downloads

1

Readme

nv-buf-read-byte

  • nv-buf-read-byte
  • read just one-byte from file
  • this is for test nvlang's byte-stream interpreter(parse unknown code char-by-char from remote),normally USELESS

install

  • npm install nv-buf-read-byte

usage

   const creat = require("nv-buf-read-byte"); 

   var ctx  = creat(filename,buf_size=4096,max_element_size=4) ;  // buf_size must >= max_element_size * 3

   ctx.read_byte(index)
   ctx.read_byte(index)
   
   .....
   
   ctx.release() 

verify

    const fs = require("fs");

    function verify(fn="./index.js",bufsz=4096) {
        let begin = (new Date).getTime();
        var  buf    = fs.readFileSync(fn);
        var small   = creat(fn,bufsz);
        var i;
        for(i=0;i<buf.length;i++) {
            let orig = buf[i];
            let curr = small.read_byte(i);
            if(orig === curr) {
            } else {
                small.release()
                throw(i)
            }
        }
        let end = (new Date).getTime();
        return({
            sz:buf.length,
            small,
            i,
            cost: (end - begin)
        })
    }

small

        var r = verify("./index.js",4096);
        /*
        {
          sz: 2829,
          small: Ctx {
            buf: <Buffer 63 6f 6e 73 74 20 7b 5f 75 2c 5f 6e 2c 5f 74 2c 5f 66 7d 20 20 20 20 3d 20 72 65 71 75 69 72 65 28 22 6e 76 2d 66 61 63 75 74 69 6c 2d 75 6e 74 66 22 ... 4046 more bytes>,
            fd: 21,
            si: 0,
            ei: 2829,
            sz: 2829,
            max_ele_len: 4,
            bufsz: 4096
          },
          i: 2829,
          cost: 1
        }
        */
        r.small.release();


        var r = verify("./index.js",1024);
        /*
        {
          sz: 2829,
          small: Ctx {
            buf: <Buffer 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 28 5f 75 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 20 ... 974 more bytes>,
            fd: 22,
            si: 2040,
            ei: 2829,
            sz: 2829,
            max_ele_len: 4,
            bufsz: 1024
          },
          i: 2829,
          cost: 0
        }
        */
        r.small.release()

        var r = small.verify("./index.js",64);

        /*
        {
          sz: 2829,
          small: Ctx {
            buf: <Buffer 65 61 74 5f 63 74 78 3b 0a 6e 65 77 20 43 74 78 28 66 6e 2c 62 75 66 73 7a 2c 6d 61 78 5f 65 6c 65 5f 6c 65 6e 29 3b 0a 0a 6d 6f 64 75 6c 65 2e 65 78 ... 14 more bytes>,
            fd: 23,
            si: 2820,
            ei: 2829,
            sz: 2829,
            max_ele_len: 4,
            bufsz: 64
          },
          i: 2829,
          cost: 1
        }
        */
        r.small.release()


        var r = verify("./index.js",12);
        /*
        {
          sz: 2829,
          small: Ctx {
            buf: <Buffer 63 74 78 3b 0a 61 74 5f 63 74 78 3b>,
            fd: 24,
            si: 2824,
            ei: 2829,
            sz: 2829,
            max_ele_len: 4,
            bufsz: 12
          },
          i: 2829,
          cost: 1
        }
        */

        r.small.release()

        verify("./index.js",8);
        /*
        Uncaught Error: bufsz:8 must >= max_ele_len:4 * 3
            at creat_err (/mnt/sda3/NV6-/nvbuf/pkgs/nv-buf-read-byte/node_modules/nv-facutil-thrw/index.js:4:29)
            at thrw_str (/mnt/sda3/NV6-/nvbuf/pkgs/nv-buf-read-byte/node_modules/nv-facutil-thrw/index.js:5:36)
            at new Ctx (/mnt/sda3/NV6-/nvbuf/pkgs/nv-buf-read-byte/index.js:61:13)
            at creat_ctx (/mnt/sda3/NV6-/nvbuf/pkgs/nv-buf-read-byte/index.js:98:52)
            at verify (REPL26:4:19)
        */

big

        const {_psj}  = require("nv-facutil-promise");


        const fs = require("fs");

        function verify(fn="/mnt/nas/webrtc.tar",bufsz=4096) {
            let begin     = (new Date).getTime();
            var total    = fs.lstatSync(fn).size;
            var small     = creat(fn,bufsz);
            var cursor    = 0;
            let [p,rs,rj] = _psj();
            var rs$       = fs.createReadStream(fn);
            rs$.on("data",(data)=>{
                for(let i=0;i<data.length;i++) {
                    let orig = data[i];
                    let curr = small.read_byte(cursor);
                    if(orig === curr) {
                        ++cursor;
                    } else {
                        small.release();
                        rj({
                            sz:total,
                            small,
                            cursor,
                        })
                    }             
                }
            });
            rs$.on("end",()=>{
                 let end = (new Date).getTime();
                 rs({
                      sz:total,
                      small,
                      cursor,
                      cost: (end - begin)         
                 })
            })
            return(p);
        }



        fs.lstatSync("/mnt/nas/webrtc.tar")
        /*
        Stats {
          dev: 78,
          mode: 33261,
          nlink: 1,
          uid: 0,
          gid: 0,
          rdev: 0,
          blksize: 1048576,
          ino: 76414987,
          size: 21592446325,
          blocks: 42174464,
          atimeMs: 1650852163805.1646,
          mtimeMs: 1650852163805.1646,
          ctimeMs: 1650852163805.1646,
          birthtimeMs: 1650851790823.6287,
          atime: 2022-04-25T02:02:43.805Z,
          mtime: 2022-04-25T02:02:43.805Z,
          ctime: 2022-04-25T02:02:43.805Z,
          birthtime: 2022-04-25T01:56:30.824Z
        }
        */


            r = await verify("/mnt/nas/webrtc.tar",4096);
            r.small.release();
        /*

        {
          sz: 21592446325,
          small: Ctx {
            buf: <Buffer bb 9c 01 70 08 6f e9 9d 73 a3 df ca 72 5c ab bc 27 d4 bc 67 d8 91 97 54 75 67 3d b3 51 a9 79 8f 74 ee c1 bb d0 0e 13 cb 2a 22 ea 8b 63 19 ac e9 44 ba ... 4046 more bytes>,
            fd: 21,
            si: 21592444632,
            ei: 21592446325,
            sz: 21592446325,
            max_ele_len: 4,
            bufsz: 4096
          },
          cursor: 21592446325,
          cost: 949770
        }
        */

test

            function loop() {
                let begin     = (new Date).getTime();
                for(let i=0;i<21592446325;++i) {}
                let end = (new Date).getTime();
                return(end - begin)
            }

            /*
              > loop()
                24129
              > 

              empty loop need 24 seconds 

            */


            function tst(fn="/mnt/nas/webrtc.tar",bufsz=4096) {
                let begin     = (new Date).getTime();
                    var total    = fs.lstatSync(fn).size;
                    var small     = creat(fn,bufsz);
                    var lst;
                    for(let i=0;i<total;++i) {
                         lst = small.read_byte(i)
                    }
                let end = (new Date).getTime();
                     return({
                          sz:total,
                          small,
                          lst,
                          cost: (end - begin)
                     })
            }



                r = await tst("/mnt/nas/webrtc.tar",4096);
                r.small.release();


            /*


                {
                  sz: 21592446325,
                  small: Ctx {
                    buf: <Buffer bb 9c 01 70 08 6f e9 9d 73 a3 df ca 72 5c ab bc 27 d4 bc 67 d8 91 97 54 75 67 3d b3 51 a9 79 8f 74 ee c1 bb d0 0e 13 cb 2a 22 ea 8b 63 19 ac e9 44 ba ... 4046 more bytes>,
                    fd: 23,
                    si: 21592444632,
                    ei: 21592446325,
                    sz: 21592446325,
                    max_ele_len: 4,
                    bufsz: 4096
                  },
                  lst: 202,
                  cost: 602217
                }

            */    
       

METHODS

       ctx.read_byte(index) 


      ctx.release()

      //// 

      ctx.is_idx_in_buf            
      ctx.read_byte_if_idx_in_buf  


      ctx.buf                      
      ctx.bufsz                    
      ctx.ei                       
      ctx.fd                       
      ctx.max_ele_len
      ctx.si                       
      ctx.sz

API

LICENSE

  • ISC