ID EN
Miscellaneous

memCompress

R Base 3.6.2 🇮🇩 Bahasa Indonesia

Kompresi atau dekompresi dalam memori untuk vektor mentah.

Syntax

R
memCompress(from, type = c("gzip", "bzip2", "xz", "none"))<p></p><p>memDecompress(from,
              type = c("unknown", "gzip", "bzip2", "xz", "none"),
              asChar = FALSE)</p>

Arguments

Parameter Deskripsi
from A raw vector. For memCompress a character vector will be converted to a raw vector with character strings separated by "\n".
type character string, the type of compression. May be abbreviated to a single letter, defaults to the first of the alternatives.
asChar logical: should the result be converted to a character string?

Return Value

Vektor mentah atau string karakter (jika asChar = TRUE).

Details

type = "none" meneruskan input tanpa perubahan, tetapi mungkin berguna jika type adalah variabel. type = "unknown" mencoba mendeteksi jenis kompresi yang diterapkan (jika ada): ini akan selalu berhasil untuk kompresi bzip2, dan akan berhasil untuk bentuk lain jika ada header yang sesuai. Ini akan secara otomatis mendeteksi header 'ajaib' ("\x1f\x8b") yang ditambahkan ke file oleh program gzip (dan ke file yang ditulis oleh gzfile), tetapi memCompress tidak menambahkan header seperti itu. kompresi bzip2 selalu menambahkan header ("BZh"). Mengompresi dengan type = "xz" sama dengan mengompresi file dengan xz -9e (termasuk menambahkan header 'ajaib'): dekompresi harus mengatasi konten file apa pun yang dikompresi dengan xz versi 4.999 dan beberapa versi lzma. Ada versi lain, khususnya aliran 'mentah', yang tidak terkini

Contoh

Example
R
# NOT RUN {
txt <- readLines(file.path(R.home("doc"), "COPYING"))
sum(nchar(txt))
txt.gz <- memCompress(txt, "g")
length(txt.gz)
txt2 <- strsplit(memDecompress(txt.gz, "g", asChar = TRUE), "\n")[[1]]
stopifnot(identical(txt, txt2))
txt.bz2 <- memCompress(txt, "b")
length(txt.bz2)
## can auto-detect bzip2:
txt3 <- strsplit(memDecompress(txt.bz2, asChar = TRUE), "\n")[[1]]
stopifnot(identical(txt, txt3))

## xz compression is only worthwhile for large objects
txt.xz <- memCompress(txt, "x")
length(txt.xz)
txt3 <- strsplit(memDecompress(txt.xz, asChar = TRUE), "\n")[[1]]
stopifnot(identical(txt, txt3))
# }

See Also

connections. extSoftVersion for the versions of the zlib bzip2 and xz libraries in use. https://en.wikipedia.org/wiki/Data_compression for background on data compression http://zlib.net/ https://en.wikipedia.org/wiki/Gzip http://www.bzip.org/ https://en.wikipedia.org/wiki/Bzip2 http://tukaani.org/xz/ and https://en.wikipedia.org/wiki/Xz for references about the particular schemes used.