Skip to content

Commit 49d8ced

Browse files
committed
added | added reStructuredText version of README file.
1 parent 29126ee commit 49d8ced

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

README.rst

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
###############
2+
BaseCon Project
3+
###############
4+
5+
`README中文文档 <https://github.com/copyrighthero/BaseCon/blob/master/README.zh-CN.md>`_
6+
7+
About the BaseCon Library
8+
=========================
9+
10+
BaseCon is a single class library for converting integers into base 2 - 65 encoded, url-safe, strings. It is simple to use and sometimes very fast for it utilizes built-in functions like `bin`, `oct`, `str` and `hex` when converting integers to base 2, 8, 10, 16 encoded strings; and it uses `int` when converting base 2 - 36 encoded strings into integers.
11+
12+
This library, however, is not compatible with the builtin base64 converter as one of the main purpose of this library is to keep the converted string url-safe. And the library currently does not support converting binary data.
13+
14+
One can use this library, for example, to create short link handles when using with auto increment database insertions, which can keep the generated handles short.
15+
16+
How to Use BaseCon Library
17+
==========================
18+
19+
After installation with `pip install BaseCon`, simply import BaseCon, instantiate and use with `encode` (`convert`) and `decode` (`revert`) methods. The default base is 62 for it only uses 0-9, A-Z and a-z when encoding. One can simply change the base when instantiating.
20+
21+
.. code-block:: python
22+
23+
from basecon import BaseCon
24+
25+
basecon = BaseCon() # default base is 62
26+
# encode integer
27+
basecon(100) # '1c', __call__ method
28+
basecon.encode(100) # '1c'
29+
basecon.convert(100) # '1c
30+
# decode string
31+
basecon('1c', False) # 100
32+
basecon.decode('1c') # 100
33+
basecon.revert('1c') # 100
34+
35+
# change the base
36+
basecon = BaseCon(16) # change the base to 16
37+
basecon(128) # '80'
38+
basecon.encode(128) # '80'
39+
basecon.convert(128) # '80'
40+
basecon('80', False)
41+
basecon.decode('80')
42+
basecon.revert('80')
43+
44+
BaseCon Class API References
45+
============================
46+
47+
`BaseCon` class is the only class exported for this library.
48+
49+
Signature: `BaseCon(base = 62)`
50+
51+
BaseCon Class
52+
-------------
53+
54+
`encode(data)` or `convert(data)`: encode an integer to string
55+
`decode(data)` or `revert(data)`: decode a string to integer
56+
`__call__(data, switch = True)`: encode/decode a payload, if switch is set to True, then it encodes; if it is set to False then it decodes.
57+
58+
Licenses
59+
========
60+
61+
This project is licensed under two permissive licenses, please chose one or both of the licenses to your like. Although not necessary, bug reports or feature improvements, attributes to the author(s), information on how this program is used are welcome and appreciated :-) Happy coding
62+
63+
[BSD-2-Clause License]
64+
65+
Copyright 2018 Hansheng Zhao
66+
67+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
68+
69+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
70+
71+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
72+
73+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
74+
75+
[MIT License]
76+
77+
Copyright 2018 Hansheng Zhao
78+
79+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
80+
81+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
82+
83+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)