1

.gz ファイルを表示 (または編集) するとき、vim は gunzip を見つけてファイルを適切に表示することを認識しています。
そのような場合、getfsize(expand("%")) は gzip されたファイルのサイズになります。

展開されたファイルのサイズを取得する方法はありますか?

[編集]
これを解決する別の方法は、現在のバッファのサイズを取得することかもしれませんが、vim にはそのような機能がないようです。何か不足していますか?

4

4 に答える 4

1

gzip 圧縮されたファイルの圧縮されていないサイズを取得する簡単な方法はありません。圧縮を解除して getfsize() 関数を使用する以外に方法はありません。それはあなたが望むものではないかもしれません。RFC 1952 - GZIP File Format Specificationを調べたところ、役立つ可能性があるのは ISIZE フィールドだけで、「...元の (圧縮されていない) 入力データのモジュロ 2^32 のサイズ」が含まれています。

編集:

これが役立つかどうかはわかりませんが、gzip で圧縮されたファイルの ISIZE フィールドの値を取得する、概念実証の C コードをまとめました。Linux と gcc を使用して動作しますが、マイレージは異なる場合があります。コードをコンパイルし、gzip されたファイル名をパラメーターとして渡すと、元のファイルの圧縮されていないサイズがわかります。

#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's 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;
}
于 2009-01-08T22:33:37.103 に答える
1

これは、バッファのバイト数を取得するために機能するようです

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

于 2009-01-12T09:23:06.690 に答える
0

vimエディター内から、これを試してください:

<Esc>:!wc -c my_zip_file.gz

これにより、ファイルのバイト数が表示されます。

于 2009-08-12T14:57:46.503 に答える
0

Unix/Linuxを使用している場合は、試してください

:%!wc -c 

それはバイト単位です。(たとえば cygwin がインストールされていれば、Windows で動作します。) 次に、 を押してuコンテンツを取り戻します。

HTH

于 2009-01-08T22:21:20.980 に答える