Questions tagged [unpack]

A function in several scripting languages for unpacking binary data into native types for the language in question. The opposite of the 'pack' function. For the Python concept, use 'iterable-unpacking'. This tag should be used with a programming language tag as well. While also used as directive or pragma in some compilers to ignore standard variable alignment for data aggregates (i.e. struct), do not use this tag for posts on that subject.

The unpack function parses a binary string into several variables with types that are native to the language in question. The binary string usually matches the machine-level representation that you would see in a C . The inverse operation is .

For Python use .

Most versions of unpack and pack functions use a format or template that specifies the byte by byte layout of the data being copied out of or put into the memory area containing the binary representation.

Both functions allow the use of C or C++ routines with complex data structures to be used with the scripting language in order to improve application performance or to perform operations and actions not available in the scripting language.

Documentation:

615 questions
8
votes
3 answers

Write and read Datetime to binary format in Python

I want to store a list of datetimes in a binary file in Python. EDIT: by "binary" I mean the best digital representation for each datatype. The application for this is to save GPS trackpoints composed by (unix-timestamp, latitude, longitude,…
heltonbiker
  • 26,657
  • 28
  • 137
  • 252
7
votes
3 answers

python struct unpack into a dict

struct.unpack will unpack data into a tuple. Is there an equivalent that will store data into a dict instead? In my particular problem, I am dealing with a fixed-width binary format. I want to be able, in one fell swoop, to unpack and store the…
Foo Bah
  • 25,660
  • 5
  • 55
  • 79
7
votes
2 answers

packing and unpacking data structure with Perl6

on perl5 if someone want to parse binary file he has the pack/unpack utiltiy where he can convert binary structure to perl variables and vice verca , is there now a production equivlant for pack/unpack on perl6 ,as from the documentation i found…
smith
  • 3,232
  • 26
  • 55
7
votes
6 answers

How to create a .BAT file to download and unpack a zip file?

How to create a .BAT file to download and unpack a zip file from HTTP server? We have links like http://example.com/folder.zip and absolute folder link like C:\Users\UserName\Some mixed Русский English Adress\ if files from zip exist in directory…
Rella
  • 65,003
  • 109
  • 363
  • 636
7
votes
1 answer

Can I use unpack to split a string into characters in Perl?

A common 'Perlism' is generating a list as something to loop over in this form: for($str=~/./g) { print "the next character from \"$str\"=$_\n"; } In this case the global match regex returns a list that is one character in turn from the string $str,…
dawg
  • 98,345
  • 23
  • 131
  • 206
7
votes
1 answer

Why is hex -> base64 so different from base64 -> hex using pack and unpack?

I got this code working, which converts from hex to base64, and vice versa. I got to_base64 from another SO question, and I wrote to_hex with some guesswork and trial and error. class String def to_base64 [[self].pack("H*")].pack("m0") …
Jonah
  • 15,806
  • 22
  • 87
  • 161
7
votes
2 answers

Reverting unpack('C*', "string")

I would like to know how I can reverse what this unpack function bellow performed. I think the pack function is able to reverse what unpack performed, however I'm not sure. First I have a simple string which after unpacking it I would have an array…
Fábio Antunes
  • 16,984
  • 18
  • 75
  • 96
6
votes
5 answers

Pythonic way to unpack an iterator inside of a list

I'm trying to figure out what is the pythonic way to unpack an iterator inside of a list. For example: my_iterator = zip([1, 2, 3, 4], [1, 2, 3, 4]) I have come with the following ways to unpack my iterator inside of a list: 1) my_list =…
kederrac
  • 16,819
  • 6
  • 32
  • 55
6
votes
6 answers

Can you explain the bits I'm getting from unpack?

I'm relatively inexperienced with Perl, but my question concerns the unpack function when getting the bits for a numeric value. For example: my $bits = unpack("b*", 1); print $bits; This results in 10001100 being printed, which is 140 in decimal.…
Rob
  • 107
  • 1
  • 7
6
votes
1 answer

Python: reading 12 bit packed binary image

I have a 12 bit packed image from a GigE camera. It is a little-endian file and each 3 bytes hold 2 12-bit pixels. I am trying to read this image using python and I tried something like this: import bitstring import numpy with…
Ivan
  • 65
  • 1
  • 4
6
votes
1 answer

Haskell: GADT with UNPACK Pragma

UNPACK supports normal data types, as shown in the following: data T = T {-# UNPACK #-} ! Int But is there a way to use the UNPACK Pragma with GADT?
Ray Qiu
  • 171
  • 5
6
votes
3 answers

Unpack rar archives in R

I need to unpack zip and rar archives, also that must be a multiplatform solution. In R you can unpack zip easily by command unzip(filename, exdir=‘’) But I found I can’t unpack rar files that way. On OS X I can simply open archive to unpack it, if…
randomsuffer
  • 353
  • 2
  • 7
  • 15
6
votes
1 answer

Including an unpacked War in the Assembly

I have a project which builds a war (no problem). And, that war needs to be packaged with a few shell scripts. Because that war contains properties files that vary from site-to-site, we can't simply install the war as is, but munge the properties…
David W.
  • 105,218
  • 39
  • 216
  • 337
6
votes
1 answer

Lua trouble: attempt to call global 'unpack' (a nil value)

I am relatively new to Lua, and am experimenting with embedding it in a library. I can execute the script just fine from the command line, but I hit the following error when calling a function in my script when embedded PANIC: unprotected error in…
learnvst
  • 15,455
  • 16
  • 74
  • 121
6
votes
2 answers

How can I parse space separated STDIN hex strings unpacked in Perl?

I have a Java program that spits out, in space-separated hexadecimal format, 16 bytes of raw packet received over the network. Since I dont want to change that code, I am piping the result to a Perl script that, theoretically, can simply unpack this…
intiha
  • 319
  • 1
  • 3
  • 13
1 2
3
40 41