2012-02-06 85 views

回答

3

下面是做到這一點的一種方法:

split(Bin, LenPart) -> 
    lists:reverse(split1(Bin, LenPart, [])). 

split1(Bin, LenPart, Acc) when byte_size(Bin) =< LenPart -> 
    [Bin | Acc]; 
split1(Bin, LenPart, Acc) -> 
    <<Part:LenPart/binary, Rest/binary>> = Bin, 
    split1(Rest, LenPart, [Part | Acc]).