We show that the collapsar model of gamma-ray bursts results in a series of successive shocks and rarefaction waves propagating in the “ cork ” of stellar material being pushed ahead of the jet , as it emerges from the massive stellar progenitor . Our results are derived from analytical calculations assuming a hot , ultrarelativistic 1-D flow with an initial Lorentz factor \Gamma _ { j } \sim 100 . The shocks result in a series of characteristic , increasingly shorter and harder thermal X-ray pulses , as well as a non-thermal \gamma -ray pulse , which precede the usual non-thermal MeV \gamma -rays . We consider jets escaping from both compact ( CO or He dwarf ) and blue supergiant stellar progenitors . The period , fluence and hardness of the pulses serves as a diagnostic for the size and density of the outer envelope of the progenitor star .