@@ -666,12 +666,12 @@ end
666666 throw (ArgumentError (" byte is not an ASCII hexadecimal digit" ))
667667
668668"""
669- bytes2hex(a::AbstractArray{UInt8} ) -> String
670- bytes2hex(io::IO, a::AbstractArray{UInt8} )
669+ bytes2hex(itr ) -> String
670+ bytes2hex(io::IO, itr )
671671
672- Convert an array `a ` of bytes to its hexadecimal string representation, either
673- returning a `String` via `bytes2hex(a )` or writing the string to an `io` stream
674- via `bytes2hex(io, a )`. The hexadecimal characters are all lowercase.
672+ Convert an iterator `itr ` of bytes to its hexadecimal string representation, either
673+ returning a `String` via `bytes2hex(itr )` or writing the string to an `io` stream
674+ via `bytes2hex(io, itr )`. The hexadecimal characters are all lowercase.
675675
676676# Examples
677677```jldoctest
@@ -689,17 +689,19 @@ julia> bytes2hex(b)
689689"""
690690function bytes2hex end
691691
692- function bytes2hex (a:: Union{Tuple{Vararg{UInt8}}, AbstractArray{UInt8}} )
693- b = Base. StringVector (2 * length (a))
694- @inbounds for (i, x) in enumerate (a)
692+ function bytes2hex (itr)
693+ eltype (itr) === UInt8 || throw (ArgumentError (" eltype of iterator not UInt8" ))
694+ b = Base. StringVector (2 * length (itr))
695+ @inbounds for (i, x) in enumerate (itr)
695696 b[2 i - 1 ] = hex_chars[1 + x >> 4 ]
696697 b[2 i ] = hex_chars[1 + x & 0xf ]
697698 end
698699 return String (b)
699700end
700701
701- function bytes2hex (io:: IO , a:: Union{Tuple{Vararg{UInt8}}, AbstractArray{UInt8}} )
702- for x in a
702+ function bytes2hex (io:: IO , itr)
703+ eltype (itr) != UInt8 && throw (ArgumentError (" eltype of iterator not UInt8" ))
704+ for x in itr
703705 print (io, Char (hex_chars[1 + x >> 4 ]), Char (hex_chars[1 + x & 0xf ]))
704706 end
705707end
0 commit comments