Link to home
Start Free TrialLog in
Avatar of ToddBPeterson
ToddBPeterson

asked on

PHP Unzipping a Byte Array

Hi All,

I have a PHP application that is consuming a .Net Web Service.  The .Net Web Service returns a CSV file that is Zipped using .Net's ZipOutputStream, and ultimately returned as a Byte Array.

I can't seem to figure out, or find a thread describing how to UnZip/Parse that result such that I end up with an in memory CSV file, or whether I write one to disk.  I'm not particularly picky at this point...  I just want to see the contents of the CSV, as I would expect.

Any thoughts?

Thanks so much!
Todd
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Please show us the response from the service (zipped) and the clear-text response that you expect,thanks, ~Ray
Avatar of ToddBPeterson
ToddBPeterson

ASKER

When I do a var_dump() of the byte array response, I get the following:

array(256) { [0]=> int(80) [1]=> int(75) [2]=> int(3) [3]=> int(4) [4]=> int(45) [5]=> int(0) [6]=> int(0) [7]=> int(0) [8]=> int(8) [9]=> int(0) [10]=> int(75) [11]=> int(54) [12]=> int(130) [13]=> int(66) [14]=> int(204) [15]=> int(213) [16]=> int(182) [17]=> int(183) [18]=> int(255) [19]=> int(255) [20]=> int(255) [21]=> int(255) [22]=> int(255) [23]=> int(255) [24]=> int(255) [25]=> int(255) [26]=> int(11) [27]=> int(0) [28]=> int(20) [29]=> int(0) [30]=> int(67) [31]=> int(111) [32]=> int(110) [33]=> int(116) [34]=> int(97) [35]=> int(99) [36]=> int(116) [37]=> int(115) [38]=> int(88) [39]=> int(109) [40]=> int(108) [41]=> int(1) [42]=> int(0) [43]=> int(16) [44]=> int(0) [45]=> int(110) [46]=> int(0) [47]=> int(0) [48]=> int(0) [49]=> int(0) [50]=> int(0) [51]=> int(0) [52]=> int(0) [53]=> int(96) [54]=> int(0) [55]=> int(0) [56]=> int(0) [57]=> int(0) [58]=> int(0) [59]=> int(0) [60]=> int(0) [61]=> int(37) [62]=> int(139) [63]=> int(65) [64]=> int(10) [65]=> int(131) [66]=> int(64) [67]=> int(12) [68]=> int(0) [69]=> int(239) [70]=> int(11) [71]=> int(251) [72]=> int(147) [73]=> int(188) [74]=> int(66) [75]=> int(161) [76]=> int(30) [77]=> int(220) [78]=> int(22) [79]=> int(241) [80]=> int(7) [81]=> int(161) [82]=> int(166) [83]=> int(221) [84]=> int(208) [85]=> int(221) [86]=> int(4) [87]=> int(146) [88]=> int(84) [89]=> int(240) [90]=> int(247) [91]=> int(10) [92]=> int(222) [93]=> int(102) [94]=> int(96) [95]=> int(230) [96]=> int(193) [97]=> int(230) [98]=> int(241) [99]=> int(194) [100]=> int(78) [101]=> int(80) [102]=> int(240) [103]=> int(134) [104]=> int(156) [105]=> int(86) [106]=> int(117) [107]=> int(135) [108]=> int(194) [109]=> int(17) [110]=> int(237) [111]=> int(146) [112]=> int(73) [113]=> int(109) [114]=> int(83) [115]=> int(129) [116]=> int(149) [117]=> int(119) [118]=> int(50) [119]=> int(204) [120]=> int(105) [121]=> int(54) [122]=> int(118) [123]=> int(22) [124]=> int(120) [125]=> int(18) [126]=> int(245) [127]=> int(31) [128]=> int(73) [129]=> int(78) [130]=> int(99) [131]=> int(69) [132]=> int(107) [133]=> int(76) [134]=> int(176) [135]=> int(80) [136]=> int(196) [137]=> int(241) [138]=> int(53) [139]=> int(221) [140]=> int(239) [141]=> int(159) [142]=> int(58) [143]=> int(218) [144]=> int(1) [145]=> int(195) [146]=> int(95) [147]=> int(54) [148]=> int(127) [149]=> int(87) [150]=> int(205) [151]=> int(233) [152]=> int(35) [153]=> int(208) [154]=> int(174) [155]=> int(250) [156]=> int(4) [157]=> int(80) [158]=> int(75) [159]=> int(1) [160]=> int(2) [161]=> int(45) [162]=> int(0) [163]=> int(45) [164]=> int(0) [165]=> int(0) [166]=> int(0) [167]=> int(8) [168]=> int(0) [169]=> int(75) [170]=> int(54) [171]=> int(130) [172]=> int(66) [173]=> int(204) [174]=> int(213) [175]=> int(182) [176]=> int(183) [177]=> int(255) [178]=> int(255) [179]=> int(255) [180]=> int(255) [181]=> int(255) [182]=> int(255) [183]=> int(255) [184]=> int(255) [185]=> int(11) [186]=> int(0) [187]=> int(20) [188]=> int(0) [189]=> int(0) [190]=> int(0) [191]=> int(0) [192]=> int(0) [193]=> int(0) [194]=> int(0) [195]=> int(0) [196]=> int(0) [197]=> int(0) [198]=> int(0) [199]=> int(0) [200]=> int(0) [201]=> int(0) [202]=> int(0) [203]=> int(67) [204]=> int(111) [205]=> int(110) [206]=> int(116) [207]=> int(97) [208]=> int(99) [209]=> int(116) [210]=> int(115) [211]=> int(88) [212]=> int(109) [213]=> int(108) [214]=> int(1) [215]=> int(0) [216]=> int(16) [217]=> int(0) [218]=> int(110) [219]=> int(0) [220]=> int(0) [221]=> int(0) [222]=> int(0) [223]=> int(0) [224]=> int(0) [225]=> int(0) [226]=> int(96) [227]=> int(0) [228]=> int(0) [229]=> int(0) [230]=> int(0) [231]=> int(0) [232]=> int(0) [233]=> int(0) [234]=> int(80) [235]=> int(75) [236]=> int(5) [237]=> int(6) [238]=> int(0) [239]=> int(0) [240]=> int(0) [241]=> int(0) [242]=> int(1) [243]=> int(0) [244]=> int(1) [245]=> int(0) [246]=> int(77) [247]=> int(0) [248]=> int(0) [249]=> int(0) [250]=> int(157) [251]=> int(0) [252]=> int(0) [253]=> int(0) [254]=> int(0) [255]=> int(0) }


What I'm hoping to be able to see, when I uncompress and parse the byte array is:

ID,FirstName,LastName,Title,City,State,Country,Phone,Email,Website,TwitterAccount,LinkedInAccount,FacebookAccount,Address1,Zip,PURL,IsSeed,Company,Mobile,PhotoURL
1,Ross,Little,,Buffalo,NY,,,rlittle@123.com,,,,,,14206,RossLittle,FALSE,,,
2,Gordon,Rivera,,Santa Maria,CA,,,gRivera@123.com,,,,,,93454,GordonRivera,FALSE,,,
3,Krisin,Meemken,,Minneapolis,MN,,,kmeemken@123.com,,,,,,55411-3422,KrisinMeemken,FALSE,,,
4,Charlie,Pettygrove,,Gordonsville,VA,,,cpettygrove@123.com,,,,,,22942,CharliePettygrove,FALSE,,,
5,Rosemary,Bundscho,,Houston,TX,,,rbundscho@123.com,,,,,,77073,RosemaryBundscho,FALSE,,,

Thanks,
Todd
Hmm...  It looks like what you have there is an array generated by something like this function.  But the numbers don't make any sense when compared to the expected data.
http://www.php.net/manual/en/function.count-chars.php

What is the URL of the service?  Is there any alternative format that you can use to retrieve the data (maybe ask for it in unZipped form?)
I think the clear text data I sent earlier may have been inaccurate.  Here is another example of the clear text data, and the compressed byte array.

Clear Text:
FirstName,LastName,Title Ross,Little,SallysList Gordon,Rivera, Krisin,Meemken,SallysList Charlie,Pettygrove,SallysList Rosemary,Bundscho, fn,ln,

Compressed Byte Array
array(273) { [0]=> int(80) [1]=> int(75) [2]=> int(3) [3]=> int(4) [4]=> int(45) [5]=> int(0) [6]=> int(0) [7]=> int(0) [8]=> int(8) [9]=> int(0) [10]=> int(230) [11]=> int(130) [12]=> int(130) [13]=> int(66) [14]=> int(9) [15]=> int(156) [16]=> int(238) [17]=> int(175) [18]=> int(255) [19]=> int(255) [20]=> int(255) [21]=> int(255) [22]=> int(255) [23]=> int(255) [24]=> int(255) [25]=> int(255) [26]=> int(11) [27]=> int(0) [28]=> int(20) [29]=> int(0) [30]=> int(67) [31]=> int(111) [32]=> int(110) [33]=> int(116) [34]=> int(97) [35]=> int(99) [36]=> int(116) [37]=> int(115) [38]=> int(88) [39]=> int(109) [40]=> int(108) [41]=> int(1) [42]=> int(0) [43]=> int(16) [44]=> int(0) [45]=> int(152) [46]=> int(0) [47]=> int(0) [48]=> int(0) [49]=> int(0) [50]=> int(0) [51]=> int(0) [52]=> int(0) [53]=> int(113) [54]=> int(0) [55]=> int(0) [56]=> int(0) [57]=> int(0) [58]=> int(0) [59]=> int(0) [60]=> int(0) [61]=> int(85) [62]=> int(141) [63]=> int(193) [64]=> int(10) [65]=> int(2) [66]=> int(49) [67]=> int(12) [68]=> int(68) [69]=> int(239) [70]=> int(133) [71]=> int(254) [72]=> int(73) [73]=> int(190) [74]=> int(66) [75]=> int(65) [76]=> int(15) [77]=> int(86) [78]=> int(145) [79]=> int(117) [80]=> int(127) [81]=> int(32) [82]=> int(184) [83]=> int(209) [84]=> int(13) [85]=> int(182) [86]=> int(9) [87]=> int(36) [88]=> int(113) [89]=> int(161) [90]=> int(127) [91]=> int(111) [92]=> int(15) [93]=> int(94) [94]=> int(246) [95]=> int(52) [96]=> int(243) [97]=> int(96) [98]=> int(120) [99]=> int(115) [100]=> int(98) [101]=> int(243) [102]=> int(184) [103]=> int(97) [104]=> int(35) [105]=> int(40) [106]=> int(248) [107]=> int(47) [108]=> int(51) [109]=> int(71) [110]=> int(165) [111]=> int(156) [112]=> int(38) [113]=> int(117) [114]=> int(135) [115]=> int(194) [116]=> int(49) [117]=> int(0) [118]=> int(30) [119]=> int(88) [120]=> int(107) [121]=> int(247) [122]=> int(194) [123]=> int(30) [124]=> int(57) [125]=> int(157) [126]=> int(213) [127]=> int(22) [128]=> int(21) [129]=> int(152) [130]=> int(120) [131]=> int(35) [132]=> int(67) [133]=> int(200) [134]=> int(233) [135]=> int(98) [136]=> int(236) [137]=> int(44) [138]=> int(112) [139]=> int(37) [140]=> int(106) [141]=> int(31) [142]=> int(146) [143]=> int(221) [144]=> int(244) [145]=> int(184) [146]=> int(162) [147]=> int(85) [148]=> int(38) [149]=> int(184) [150]=> int(83) [151]=> int(68) [152]=> int(127) [153]=> int(155) [154]=> int(110) [155]=> int(123) [156]=> int(211) [157]=> int(120) [158]=> int(160) [159]=> int(134) [160]=> int(214) [161]=> int(225) [162]=> int(240) [163]=> int(149) [164]=> int(197) [165]=> int(159) [166]=> int(171) [167]=> int(14) [168]=> int(219) [169]=> int(75) [170]=> int(160) [171]=> int(202) [172]=> int(200) [173]=> int(31) [174]=> int(80) [175]=> int(75) [176]=> int(1) [177]=> int(2) [178]=> int(45) [179]=> int(0) [180]=> int(45) [181]=> int(0) [182]=> int(0) [183]=> int(0) [184]=> int(8) [185]=> int(0) [186]=> int(230) [187]=> int(130) [188]=> int(130) [189]=> int(66) [190]=> int(9) [191]=> int(156) [192]=> int(238) [193]=> int(175) [194]=> int(255) [195]=> int(255) [196]=> int(255) [197]=> int(255) [198]=> int(255) [199]=> int(255) [200]=> int(255) [201]=> int(255) [202]=> int(11) [203]=> int(0) [204]=> int(20) [205]=> int(0) [206]=> int(0) [207]=> int(0) [208]=> int(0) [209]=> int(0) [210]=> int(0) [211]=> int(0) [212]=> int(0) [213]=> int(0) [214]=> int(0) [215]=> int(0) [216]=> int(0) [217]=> int(0) [218]=> int(0) [219]=> int(0) [220]=> int(67) [221]=> int(111) [222]=> int(110) [223]=> int(116) [224]=> int(97) [225]=> int(99) [226]=> int(116) [227]=> int(115) [228]=> int(88) [229]=> int(109) [230]=> int(108) [231]=> int(1) [232]=> int(0) [233]=> int(16) [234]=> int(0) [235]=> int(152) [236]=> int(0) [237]=> int(0) [238]=> int(0) [239]=> int(0) [240]=> int(0) [241]=> int(0) [242]=> int(0) [243]=> int(113) [244]=> int(0) [245]=> int(0) [246]=> int(0) [247]=> int(0) [248]=> int(0) [249]=> int(0) [250]=> int(0) [251]=> int(80) [252]=> int(75) [253]=> int(5) [254]=> int(6) [255]=> int(0) [256]=> int(0) [257]=> int(0) [258]=> int(0) [259]=> int(1) [260]=> int(0) [261]=> int(1) [262]=> int(0) [263]=> int(77) [264]=> int(0) [265]=> int(0) [266]=> int(0) [267]=> int(174) [268]=> int(0) [269]=> int(0) [270]=> int(0) [271]=> int(0) [272]=> int(0) }

I am able to have the provider send me back an uncompressed version of the data, but only for development/testing.  I will eventually have to be able to handle the compressed byte array.  For now, however, the two data examples above should be more of an apples-to-apples comparison.

Thanks for looking at this!
Todd
I am having a hard time understanding this.  What is the URL of the service?  I would like to see their online documentation.
Sure...  The services are secured, and require authentication credentials, but I can get you to the landing/help pages.

http://studio.mdl.io/REST/contactservice/help

I am using the getContactList() method: http://studio.mdl.io/REST/contactservice/GetContactList

I hope it helps!  Thanks again for looking at this!
Todd
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank Ray!  I think I'll get by for now, as I'm merely working on a proof-of-concept, but may have to cross that bridge in the future, if I get to needing to productionalize an integration with Mindfire.

I appreciate your timely responses!

At the risk of being a cross-poster, I am having another challenge with JSON and CURL, which I've posted at: https://www.experts-exchange.com/questions/28084355/Getting-Values-From-CURLOPT-POSTFIELDS.html

If you have time, and any thoughts on that one, I would appreciate it.  Seems like a simple problem, but I'm struggling a bit, being new to JSON, and to CURL.

Thanks!
Todd