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
13
votes
6 answers

lambda arguments unpack error

In Python 2 this code is OK: f = lambda (m, k): m + k m = [1,2,3,4] k = [5,6,7,8] print(map(f, zip(m, k))) but in Python 3 the following error occurred: f = lambda (m, k): m + k ^ SyntaxError: invalid syntax If I remove parentheses in lambda…
mblw
  • 1,762
  • 1
  • 19
  • 28
13
votes
4 answers

How to unpack the contents of a JavaScript file?

You know how those packed js files look like, right? eval(function(p,a,c,k,e,d){ ... } ('obfuscated-string'.split('|'),0,{})) It just so happens to be that i have to tweak some large legacy code that looks like that and I want to find a way to turn…
Valentin Brasso
  • 1,388
  • 7
  • 21
  • 41
12
votes
1 answer

Use nlohmann json to unpack list of integers to a std::vector

I'm using nlohman::json. It's awesome, but is there any way to unpack: { "my_list" : [1,2,3] } into a std:vector ? I can't find any mention in the docs, and std::vector v = j["my_list"]; fails, as does…
P i
  • 29,020
  • 36
  • 159
  • 267
11
votes
3 answers

Maven: unpack zip artifact to a SPECIFIC folder name

I am trying to download tomcat zip artifact and unpack it int a folder named tomcat. What i get is tomcat/apache-tomcat-7.0.19/ How can I get rid of the annoying intermediate directory? org.apache.maven.plugins
archmisha
  • 199
  • 1
  • 2
  • 12
11
votes
4 answers

Python: reading 12-bit binary files

I am trying to read 12-bit binary files containing images (a video) using Python 3. To read a similar file but encoded in 16 bits, the following works very well: import numpy as np images = np.memmap(filename_video, dtype=np.uint16, mode='r',…
squille
  • 243
  • 1
  • 2
  • 10
11
votes
2 answers

Lua unpack bug?

I Have stumbled on a weird behavior in Lua unpack function table1 = {true, nil, true, false, nil, true, nil} table2 = {true, false, nil, false, nil, true, nil} a1,b1,c1,d1,e1,f1,g1 = unpack( table1 ) print…
Geggamojja
  • 145
  • 1
  • 6
10
votes
4 answers

Parsing in Perl a string separated by null bytes

The /proc filesystem contains details of running processes. For example on Linux if your PID is 123 then the command line of that process will be found in /proc/123/cmdline The cmdline is using null-bytes to separate the arguments. I suspect unpack…
emx
  • 1,295
  • 4
  • 17
  • 28
9
votes
1 answer

How to convert Hex string to IEEE754 Float number with Raku?

In Python, unpack can convert Hex string to IEEE754 Float number: import struct print(struct.unpack('
ohmycloudy
  • 629
  • 5
  • 13
9
votes
1 answer

unpack() not available on Lua 5.4?

I am reading a few tutorials on Lua and am trying to figure out how to use unpack(). I found an example that goes like this: t = { "the", "quick", "brown" } print (unpack (t)) The output should be "the quick brown". What actually happens is this:…
user1766438
  • 492
  • 4
  • 13
9
votes
1 answer

ansible - unarchive - input file not found

I'm getting this error while Ansible (1.9.2) is trying to unpack the file. 19:06:38 TASK: [jmeter | unpack jmeter] ************************************************ 19:06:38 fatal: [jmeter01.veryfast.server.jenkins] => input file not found at…
AKS
  • 16,482
  • 43
  • 166
  • 258
9
votes
3 answers

Unpacking deeply nested struct with given C header into dictionary?

I'm looking for a way to unpack binary data. The data is described by a whole tree of structs (up to four layers deep, total struct size is almost 64k) in a C header file. For this question: Unpacking nested C structs in Python the only answer was…
Jasper
  • 3,939
  • 1
  • 18
  • 35
9
votes
2 answers

How to convert UTF8 byte arrays to string in lua

I have a table like this table = {57,55,0,15,-25,139,130,-23,173,148,-24,136,158} it is utf8 encoded byte array by php unpack function unpack('C*',$str); how can I convert it to utf-8 string I can read in lua?
Tony
  • 243
  • 2
  • 5
  • 9
9
votes
1 answer

vector unpacking for octave

Octave(/matlab)'s notation for handling multiple return values [a, b] = f(x) suggests that the values returned by f(x) are in a sort of row vector and that Octave supports vector unpacking (like Python's tuple-unpacking). Yet when I put [a, b] =…
dspyz
  • 5,280
  • 2
  • 25
  • 63
8
votes
1 answer

Python - value unpacking order in method parameters

def fun(a, b, c, d): print('a:', a, 'b:', b, 'c:', c, 'd:', d) why this one works fun(3, 7, d=10, *(23,)) and prints out: a: 3 b: 7 c: 23 d: 10 while this fun(3, 7, c=10, *(23,)) does not Traceback (most recent call last): File…
Łukasz
  • 1,980
  • 6
  • 32
  • 52
8
votes
3 answers

View content files of .deb archive

I want to view the content of a .deb archive but I´m not able to unpack the .deb file with any pack program like 7Zip. When I try to install the file in Linux Ubuntu with dpkg-deb the system return the message "...is not a debian format archive".…
Hans
  • 107
  • 1
  • 4
1
2
3
40 41