How to get the size of the uploaded file in vim

When viewing (or editing) a .gz file, vim knows how to find gunzip and display the file correctly.
In such cases, getfsize (expand ("%")) will be the size of the gzipped file.

Is there a way to get the size of the extended file?

[EDIT]
Another way to solve this is to get the size of the current buffer, but there seems to be no such function in vim. Did I miss something?

+1


source to share


4 answers


There is no easy way to get the uncompressed size of a gzip file without scattering it and using the getfsize () function. This may not be what you want. I took a look at RFC 1952 - GZIP File Format Specification , and the only thing that might be useful is the ISIZE field which contains "... the size of the original (uncompressed) input mod 2 ^ 32".

EDIT:



I don't know if this helps, but here is the code behind the code I dumped together that retrieves the value of the ISIZE field in the gzip'd file. It works for me using Linux and gcc, but your mileage may vary. If you compile the code and then pass the gzip'd filename as a parameter, it will tell you the uncompressed size of the original file.

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

int main(int argc, char *argv[])
{
    FILE *fp = NULL;
    int  i=0;

    if ( argc != 2 ) {
        fprintf(stderr, "Must specify file to process.\n" );
        return -1;
    }

    // Open the file for reading
    if (( fp = fopen( argv[1], "r" )) == NULL ) {
        fprintf( stderr, "Unable to open %s for reading:  %s\n", argv[1], strerror(errno));
        return -1;
    }

    // Look at the first two bytes and make sure it a gzip file
    int c1 = fgetc(fp);
    int c2 = fgetc(fp);
    if ( c1 != 0x1f || c2 != 0x8b ) {
        fprintf( stderr, "File is not a gzipped file.\n" );
        return -1;
    }


    // Seek to four bytes from the end of the file
    fseek(fp, -4L, SEEK_END);

    // Array containing the last four bytes
    unsigned char read[4];

    for (i=0; i<4; ++i ) {
        int charRead = 0;
        if ((charRead = fgetc(fp)) == EOF ) {
            // This shouldn't happen
            fprintf( stderr, "Read end-of-file" );
            exit(1);
        }
        else
            read[i] = (unsigned char)charRead;
    }

    // Copy the last four bytes into an int.  This could also be done
    // using a union.
    int intval = 0;
    memcpy( &intval, &read, 4 );

    printf( "The uncompressed filesize was %d bytes (0x%02x hex)\n", intval, intval );

    fclose(fp);

    return 0;
}

      

+1


source


This seems to work for getting the counter byte



(line2byte(line("$")+1)-1)

+1


source


If you are using Unix / linux try

:%!wc -c 

      

It is in bytes. (It works with windows if you have cygwin, for example.) Then click u

to return the contents.

NTN

0


source


From vim editor try this:

<Esc>:!wc -c my_zip_file.gz

      

This will show you the number of bytes the file has.

0


source







All Articles