How does an air compresser work?

good question !.. you need some kind of piston to create to apply a force and give an increase in pressure, and some kind of uni-directional valve to accept the pressurised air in one direction but not the other. this is because piston mechanisms cannot provide a constant stream of pressurised air, and during the off-stroke you need to stop the pressurised air from coming back towards the input.