anchor.diff:            {element(1, B), read_tcp_stream(B, PacketArray)}}
        end || {Flow, Idxs} <- Flows ].
   
  +%%-type timestamp() :: non_neg_integer(). % Microseconds.
  +-type packet_array() :: array(). % array:array({timestamp(), packet()})
  +-spec tcp_packet_array(File::string()) -> {packet_array(),
  +                                           Count::non_neg_integer()}.
   tcp_packet_array(File) ->
       enet_pcap:file_foldl(File,
                            fun tcp_pa_fold/3,
                            {array:new(), 0}).
   
  -tcp_pa_fold(#pcap_hdr{datalinktype=Link},
  +tcp_pa_fold(#pcap_hdr{datalinktype=Link,
  +                      endianness=Endian},
               #pcap_pkt{ts={S,US},data=P},
               {Array,Cnt}) ->
  -    Pkt = enet_codec:decode(Link, P, [null, ethernet, ipv4, ipv6, tcp]),
  +    Pkt = enet_codec:decode(Link, P, [null, {endianness, Endian},
  +                                      ethernet, ipv4, ipv6, tcp]),
       TS = (S * 1000000) + US,
       {array:set(Cnt, {TS, Pkt}, Array), Cnt + 1}.
   
   %% Classifies based on src and dst hosts and ports only. Assumes that
   %% a flow isn't re-used within a capture.
  +-spec tcp_flows(packet_array()) -> [{tcp_flow(), [packet()]}].
   tcp_flows(PacketArray) ->
       D = array:foldl(fun tcp_flow_fold/3,
                       dict:new(),
                       PacketArray),
       dict:to_list(D).
   
  -tcp_flow_parts(Flow = {A,B}, Flows, PacketArray) ->
  +-type host_port() :: {ip_address() | undefined, netport() | undefined}.
  +-type tcp_flow_part() :: { {Src::host_port(), Dst::host_port()},
  +                           [packet() | 'not_tcp'] }.
  +-spec tcp_flow_parts(tcp_flow(), tcp_flows(), packet_array()) ->
  +                            { Forward::tcp_flow_part(),
  +                              Reverse::tcp_flow_part() }.
  +tcp_flow_parts(Flow = {_A,_B}, Flows, PacketArray) ->
       Idxs = proplists:get_value(Flow, Flows),
       tcp_flow_parts2(Flow, Idxs, PacketArray).
   
  -tcp_flow_parts2(Flow = {A,B}, Idxs, PacketArray) ->
  +tcp_flow_parts2({A,B}, Idxs, PacketArray) ->
       { {{A,B},
          [ I || I <- Idxs,
                 tcp_flow(element(2, array:get(I, PacketArray))) =:= {A,B} ]},
  
positive.code:         _ -> not_tcp
      end;
  tcp_flow(_) -> not_tcp.
      
  tcp_flow(Srcaddr, Srcport, Dstaddr, Dstport) ->
      Src = {Srcaddr, Srcport},
      Dst = {Dstaddr, Dstport},
      {Src, Dst}.
  
  tcp_flow_sort(Data) ->
      {A,B} = tcp_flow(Data),
      {erlang:min(A, B), erlang:max(A, B)}.
  
  tcp_flow_fold(Idx, {_TS,Pkt}, FlowD) ->
      case tcp_flow_sort(Pkt) of
  
negative.code: -export([read_tcp_stream/2,
           read_tcp_streams/1]).
  
  -type packet() :: #null{} | #eth{} | #ipv4{} | #ipv6{} | #tcp{}.
  -type tcp_flow() :: {{Src::ip_address(), SrcPort::port_no()},
                       {Dst::ip_address(), DstPort::port_no()}}.
  -type tcp_flows() :: [tcp_flow()].
  
  -spec read_tcp_streams(FileName::string()) -> tcp_flows().
  read_tcp_streams(File) ->
      {PacketArray, _Count} = tcp_packet_array(File),
      Flows = tcp_flows(PacketArray),
  