Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a recommended way to convert the output into a string? #148

Closed
papb opened this issue May 21, 2021 · 2 comments
Closed

Is there a recommended way to convert the output into a string? #148

papb opened this issue May 21, 2021 · 2 comments

Comments

@papb
Copy link

papb commented May 21, 2021

I've noticed that this module returns an array of numbers. Is there a recommended way to convert the output into a string?

I could use .join(',') for example, but I feel that such approach is contrary to the idea of compression. Surely a lot more information could fit in a string if I use all printable ASCII characters instead of only numbers and a comma.

Thanks!!

@floydpink
Copy link
Owner

Duplicate of #147

@floydpink floydpink marked this as a duplicate of #147 May 21, 2021
@papb
Copy link
Author

papb commented May 21, 2021

Hello, why did you think this is a duplicate of my other question? Maybe if I add some code it will make it more clear:

const lzwcompress = require('lzwcompress');

const data = [{
	foo: ['bar', { baz: 123 }],
	foobar: {
		abc123: true
	}
}];

const compressed = lzwcompress.pack(data);
console.log(compressed);

Output:

[
  123,  34,  95,  95, 107,  34,  58,  91,  34, 102, 111,
  111,  34,  44,  34,  98,  97, 122, 268, 264, 266, 271,
  114, 274,  97,  98,  99,  49,  50,  51,  34,  93, 269,
  258, 118, 261,  91, 256,  48, 291, 270,  97, 278,  44,
  256,  49, 261, 283,  51, 125, 287,  34,  50, 261, 256,
  285,  58, 116, 114, 117, 101, 125, 305, 125
]

The question: is there a recommended way to convert this array of numbers into a string in the context of LZW? I could do compressed.join(',') of course but I think it is likely for another recommended way to exist. (Of course, I would also need a way to un-convert later as a pre-unpack step)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants