This is based on the the same principle as how toy spud guns work, but they use something more engineered to compress the air. Air guns also work in a similar way; pulling the trigger releases a large spring which pushes a piston down a cylinder. This compresses the air behind the bullet until it overcomes the friction holding it there, and then it fires down the barrel.
In fact, based on this same principle, there are designs for a gun used to fire projectiles into space. The prototype was called SHARP (Super High Altitude Research Project) and worked by using a methane-oxygen explosion to fire a piston down a tube. This then compressed hydrogen to enormous pressures, which forced the bullet/satellite up the barrel. Compared to current rocket technology, only a third of the rocket's weight would be taken up by the equipment used to project it, allowing it to get into low earth orbit far more efficiently than using present rocket technology.