floydpink/lzwCompress.js

Node Js - lzwCompress.unpack() is taking more time to decompress the json

jpnathannew opened this issue · 5 comments

lzwCompress.unpack() is taking more time to decompress the json

Apologies on the delay is responding.

It is not clear from the description as to what "taking more time" means and what the decompress operation is compared with. Can you please provide more details?

HI i just get the string from the server. like so . 123,34,95,95,107,34,58,91,34,116,121,112,101,34,44,34,100,97,116,97,34,93,270,258,118,261,256,48,261,34,99,104,273,269,34,49,284,115,293,115,34,125,125 and unable to unpack so i do something like message.utf8Data.split(','). and then there is no async. so i guess the reason why it fails?

@ssshammi - sorry, I did not fully understand the question.

Are you using this library on the server side to pack/compress data and are expecting to unpack/uncompress it at the client side?

yes on server i have nodejs. lzwCompress.js and on the client i have lzwCompress.js and i have added the code inline. so i guess somestimes it gives an error .

Fri Jan 01 2021 19:29:43 GMT+0000 (Greenwich Mean Time) Connection from origin file://.
/ Connection accepted.[object Object]
{
type: 'utf8',
utf8Data: '123,34,95,95,107,34,58,91,34,116,121,112,101,34,44,34,100,97,116,97,34,93,270,258,118,261,256,48,261,34,99,104,273,269,34,49,284,115,293,34,125,125'
}
[
'123', '34', '95', '95', '107', '34',
'58', '91', '34', '116', '121', '112',
'101', '34', '44', '34', '100', '97',
'116', '97', '34', '93', '270', '258',
'118', '261', '256', '48', '261', '34',
'99', '104', '273', '269', '34', '49',
'284', '115', '293', '34', '125', '125'
]
C:\abertay\Network computer games\Coursework\Projects\node_modules\lzwcompress\lzwCompress.js:102
if (!obj.hasOwnProperty('__k')) {
^

TypeError: Cannot read property 'hasOwnProperty' of null
at Object.decompress [as unpack] (C:\abertay\Network computer games\Coursework\Projects\node_modules\lzwcompress\lzwCompress.js:102:20)
at Object._decompress [as unpack] (C:\abertay\Network computer games\Coursework\Projects\node_modules\lzwcompress\lzwCompress.js:219:38)
at WebSocketConnection. (C:\abertay\Network computer games\Coursework\Projects\FirstServer.js:101:37)
at WebSocketConnection.emit (events.js:315:20)
at WebSocketConnection.processFrame (C:\abertay\Network computer games\Coursework\Projects\node_modules\websocket\lib\WebSocketConnection.js:554:26)
at C:\abertay\Network computer games\Coursework\Projects\node_modules\websocket\lib\WebSocketConnection.js:323:40
at processTicksAndRejections (internal/process/task_queues.js:79:11)

i tried everything for the past 2 days, now i have used json.stringify and parse. no lzwcompression. would have been good for my report but it fails if the string is too large

@ssshammi - ah, I see now. I don't think this library might be the best solution for what you're trying to do, IMHO.

Depending on the backend framework and the server, you should be able to enable gzip compression for the responses and that has the added advantage of being automatically uncompressed by most of the client-side technologies (like browser and other frontend frameworks).

This library is useful for when you want to compress and persist large JSON objects into different datastores to then unpack it on the same layer (backend/frontend) - for example, you compress before storing into browser's local-storage or IndexedDB or for your backend datastore.

Does that make sense?