33 * These are separate from common.js so they can be skipped when bundling for the browser.
44 */
55
6- const querystring = require ( 'querystring' )
6+ import querystring from 'querystring'
77
8- exports . IPV4_RE = / ^ [ \d . ] + $ /
9- exports . IPV6_RE = / ^ [ \d a - f A - F : ] + $ /
10- exports . REMOVE_IPV4_MAPPED_IPV6_RE = / ^ : : f f f f : /
8+ export const IPV4_RE = / ^ [ \d . ] + $ /
9+ export const IPV6_RE = / ^ [ \d a - f A - F : ] + $ /
10+ export const REMOVE_IPV4_MAPPED_IPV6_RE = / ^ : : f f f f : /
1111
12- exports . CONNECTION_ID = Buffer . concat ( [ toUInt32 ( 0x417 ) , toUInt32 ( 0x27101980 ) ] )
13- exports . ACTIONS = { CONNECT : 0 , ANNOUNCE : 1 , SCRAPE : 2 , ERROR : 3 }
14- exports . EVENTS = { update : 0 , completed : 1 , started : 2 , stopped : 3 , paused : 4 }
15- exports . EVENT_IDS = {
12+ export const CONNECTION_ID = Buffer . concat ( [ toUInt32 ( 0x417 ) , toUInt32 ( 0x27101980 ) ] )
13+ export const ACTIONS = { CONNECT : 0 , ANNOUNCE : 1 , SCRAPE : 2 , ERROR : 3 }
14+ export const EVENTS = { update : 0 , completed : 1 , started : 2 , stopped : 3 , paused : 4 }
15+ export const EVENT_IDS = {
1616 0 : 'update' ,
1717 1 : 'completed' ,
1818 2 : 'started' ,
1919 3 : 'stopped' ,
2020 4 : 'paused'
2121}
22- exports . EVENT_NAMES = {
22+ export const EVENT_NAMES = {
2323 update : 'update' ,
2424 completed : 'complete' ,
2525 started : 'start' ,
@@ -31,36 +31,35 @@ exports.EVENT_NAMES = {
3131 * Client request timeout. How long to wait before considering a request to a
3232 * tracker server to have timed out.
3333 */
34- exports . REQUEST_TIMEOUT = 15000
34+ export const REQUEST_TIMEOUT = 15000
3535
3636/**
3737 * Client destroy timeout. How long to wait before forcibly cleaning up all
3838 * pending requests, open sockets, etc.
3939 */
40- exports . DESTROY_TIMEOUT = 1000
40+ export const DESTROY_TIMEOUT = 1000
4141
42- function toUInt32 ( n ) {
42+ export function toUInt32 ( n ) {
4343 const buf = Buffer . allocUnsafe ( 4 )
4444 buf . writeUInt32BE ( n , 0 )
4545 return buf
4646}
47- exports . toUInt32 = toUInt32
4847
4948/**
5049 * `querystring.parse` using `unescape` instead of decodeURIComponent, since bittorrent
5150 * clients send non-UTF8 querystrings
5251 * @param {string } q
5352 * @return {Object }
5453 */
55- exports . querystringParse = q => querystring . parse ( q , null , null , { decodeURIComponent : unescape } )
54+ export const querystringParse = q => querystring . parse ( q , null , null , { decodeURIComponent : unescape } )
5655
5756/**
5857 * `querystring.stringify` using `escape` instead of encodeURIComponent, since bittorrent
5958 * clients send non-UTF8 querystrings
6059 * @param {Object } obj
6160 * @return {string }
6261 */
63- exports . querystringStringify = obj => {
62+ export const querystringStringify = obj => {
6463 let ret = querystring . stringify ( obj , null , null , { encodeURIComponent : escape } )
6564 ret = ret . replace ( / [ @ * / + ] / g, char => // `escape` doesn't encode the characters @*/+ so we do it manually
6665 `%${ char . charCodeAt ( 0 ) . toString ( 16 ) . toUpperCase ( ) } ` )
0 commit comments