Why these lines won't give me identical results?
>>> gzip.compress('same'.encode('ascii'))
b'\x1f\x8b\x08\x00\xe2\x0e0V\x02\xff+N\xccM\x05\x00D\xf1P\xfc\x04\x00\x00\x00'
>>> gzip.compress('same'.encode('ascii'))
b'\x1f\x8b\x08\x00\xe3\x0e0V\x02\xff+N\xccM\x05\x00D\xf1P\xfc\x04\x00\x00\x00'
This is quite annoying for unit testing.
The gzip header contains a modification timestamp.
See here
For unit testing, you might be able to get away with skipping the header and comparing the rest.
Something like this:
a = gzip.compress('same'.encode('ascii'))
b = gzip.compress('same'.encode('ascii'))
a[5:] == b[5:]
Not sure about the value 5 in that but that seems to be the header size it is using.
As noted, the gzip header contains a timestamp. If you pass the -n or --no-name option (to the command-line zip program) these are omitted.
Related
The following command does not append but replaces the content
echo 0 >> /sys/block/nvme0n1/queue/nomerges
I don't want to replace but append. But I'm curious Is there something special about this file?
It also doesn't allow more than one character as its input.
Look at https://serverfault.com/questions/865787/what-does-the-nomerge-mean-in-linux-system
It might help you in understanding, that there are only 3 options that the file can take.
Also:
nomerges enables the user to disable the lookup logic involved with IO
merging requests in the block layer. By default (0) all merges are
enabled. When set to 1 only simple one-hit merges will be tried. When
set to 2 no merge algorithms will be tried (including one-hit or more
complex tree/hash lookups).
I'm writing code in .csh, and I'm trying to change the bunit header for a FITS file from K (kelvin) to km/s. How can I do that?
I know in Python I would use new_fitsfile.header['BUNIT']='km/s', but that won't work in the current .csh code, and it's not an option to switch it to Python code.
If this is needed only once, call interactively fv or ds9, move to the header, edit the header card and save the result.
For generic batch jobs, one needs some online FITS editor like fmodhead fmodhead, fthedit, or my fedithead
sed "s:BUNIT = 'K ':BUNIT = 'km/s ':g" old.fits >new.fits
and be very careful to count the significant spaces.
Hi I understand that Concat is possible with Gzip function on OS File system,
i.e.
gzip -c a.txt > a.gzip
gzip -c b.txt > b.gzip
now below is also correct,
cat a.txt b.txt | gzip -c > ab.gzip # is same as
cat a.gzip b.gzip > ab.gzip
At file system this seems correct to me, but when I try to implement the same concept with node.js to concat, header (pre-gzipped content), main-content (pre-gzip), side-bar and other widgets which are pre-gzip binary data files on filesystem than it doesn't seem working for me, I can only see text content of first chunk (header) and other appended content displayed as random binary symbols.
First want to understand is it possible and if yes then how can I implement fragmented caching.
I just want to see if it is possible with compressed fragmented caching, otherwise plan B is to use plain fragmented caching and gzip content runtime.
var rs1 = fs.createReadStream('./node_fs/index/index.txt.gz');
var rs2 = fs.createReadStream('./node_fs/index/content.txt.gz');
res.write(rs1);
res.write(rs2);
Additionally, both files are compressed using gzip.exe command line and if I write only one of them than it works fine, but append doesn't work.
Your original gzip example "works" because the gunzip tool is written to handle multiple entries in a single file. It doesn't work with some browsers because they expect a single gzip entry.
See: Concatenate multiple zlib compressed data streams into a single stream efficiently
So here is what I've got:
The problem that I face requires me to take a specialized header from WAV1 , and put it as the header for WAV2, in order to make WAV2 work with the API that I'm using. However, whenever I try to replace the first 38 characters of WAV2 with the first 38 of WAV1, I get an error when I try to play the file, I get an error saying that it is not formatted properly. Both WAV1 and WAV2 play properly before the edit.
Do you guys have any idea on what I'm doing wrong?
Thanks so much for your help.
-Rhynorater.
Wav format is a standardised format (see https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ for details about file format). I'm not sure what a "specialized" header is (perhaps you could clarify what your specialised header is?) as the format is standard - any variation would not be a wav file.
The first 38 bytes of a wav file are the header and should adhere to the standard. You cannot copy the header from one file and use it for another as the header contains information specific to the individual file (number of channels, sample rate, file length, etc).
If you both files playback normally (how are you testing this?) I'm not sure why the API you are using is not compatible (which API are you using?).
I have a lot of files. Every of which contains data.
I can happy import one file to Mathematica. But there are more than 500 hundreds of files.
I do it so:
Import["~/math/third_ks/mixed_matrices/1.dat", "Table"];
aaaa = %
(*OUTPUT - some data, I can access them!*)
All that I want is just to make circle(I can do it), but I cannot change name of file - 1.dat. I want to change it.
I tried to make such solution. I generated part of possible names and I have written them to separated file.
Import["~/math/third_ks/mixed_matrices/generate_name_of_files.dat", "Table"];
aaaa = %
Output: {{"~/math/third_ks/mixed_matrices/0.dat"}, \
{"~/math/third_ks/mixed_matrices/1.dat"}, ......
All that I want to do is Table[a=Import[aaaa[[i]] ,{i,1,500}]
But the function Import accepts only String " " objects as filename/paths.
You can use FileNames to collect the names of the data files you want to import, with the usual wildcards.
And then just map the Import statement over the list of filenames.
data will then contain a list comprising the data from each file as a separate element.
data = Import[#,"Table"]& /# FileNames["~/math/third_ks/mixed_matrices/*.dat"];
It's a bit hard to work out what is going on without the file of filenames. However, I think you might be able to solve your problem by using Flatten on the list of filenames to make it a vector of String objects that can be passed to Import. Currently your list is an n*1 matrix, where each row is a List containing a String, not a vector of Strings.
Incidentally you could use Map (/#) instead of Table in this instance.
Thank you for your response.
It happened so that I got two solutions in the same time.
I think it would be not fair to forget about second way.
aaaa = "~/math/third_ks/mixed_matrices/" <> ToString[#] <> ".dat" & /# Range[0, 116];
(*This thing generates list of lines
Output:
{"~/math/third_ks/mixed_matrices/0.dat", \
"~/math/third_ks/mixed_matrices/1.dat", \
"~/math/third_ks/mixed_matrices/2.dat", .....etc, until 116
Table[Import[aaaa[[i]], "Table"], {i, 1, 117}];
(*and it just imports data from file*)
bbbb = %; (*here we have all data, voila!*)
Incidentally, it's not my solution.
It was supposed by one my friend:
https://stackoverflow.com/users/1243244/light-keeper