design patterns - Choice of direction in c# streams -
some streams in c# appear have "direction" in meant used on 1 way. of them, such filestream , networkstream makes sense, others not.
for example gzipstream can either compress or decompress data writing stream depending on constructor parameters. cryptostream on other hand force encrypted data far side decryption forced read operation , encryption write operation.
especially when working cryptographic implementations has been annoying forced pushing data in specific direction.
is there specific design motivation implementing streams in 1 direction only?
update: clarify, i'm looking understanding on why designs use single direction, not choice of direction is. did think of before , found explanation or maybe there none.
receiving running stream of data need processed possible. therefore want write bytes decoding stream received.
with cryptostream there no natural relation how many bytes put in memorystream , how many bytes can read decrypted. here must take implementation specific details consideration such block size.
gzipstream can handle changing direction of compression.
decryption forced read operation , encryption write operation
is there specific design motivation implementing streams in 1 direction only?
well, suppose other way round. sounds sensible decrypt-while-writing file, data still has come somewhere.
meaning need stream.copyto() , occasional memorystream. , tools can use well.
the choice may have been arbitrary need pick direction, , encrypt-while-writing seems (to me) natural.
Comments
Post a Comment